8

既存のWebサービスを利用しようとしていますが、これは完全に機能します。多くのチュートリアルと例を読んだ後、私はついにサーバーから答えを得ることができました:

サーバーはリクエストを処理できませんでした。オブジェクト参照がオブジェクト インスタンスに設定されていません

WSを使用すると、NTログインからIDを取得できます(1つの文字列パラメータ、1つの文字列回答)。

これが私のperlスクリプトです:

#!perl -w
use strict;
use warnings;

use LWP::UserAgent; 
use SOAP::Lite on_action => sub { "$_[0]$_[1]"; };
use LWP::Debug; LWP::Debug::level('+'); SOAP::Lite->import(+trace => 'all');
#use SOAP::Lite  +trace =>  'debug';
#sub SOAP::Transport::HTTP::Client::get_basic_credentials { return ('user' => 'pwd') };
use Data::Dumper;

my $var = SOAP::Data->new(name => 'NTLogin', value => "1234", type =>'s:string');

my $resultLogin = SOAP::Lite
  -> uri('http://xxxxx')
  -> proxy('http://yyyyy/zzzzz/directory.asmx')
  -> on_action( sub { join '/', @_ } )
  -> GetUIDFromNTLogin($var);

print "lets test it...\n\n";

  print $resultLogin;
  print "\nresult():\n";
  print $resultLogin->result();

そして、これが出力です:

Launching NT to UID conversion
SOAP::Data::new: ()
SOAP::Lite::new: ()
LWP::UserAgent::new: ()
SOAP::Transport::HTTP::Client::new: ()
SOAP::Lite::call: ()
SOAP::Serializer::envelope: ()
SOAP::Serializer::envelope: GetUIDFromNTLogin SOAP::Data=HASH(0x______)
SOAP::Data::new: ()
SOAP::Data::new: ()
SOAP::Data::new: ()
SOAP::Data::new: ()
SOAP::Data::new: ()
SOAP::Transport::HTTP::Client::send_receive: HTTP::Request=HASH(0x______)
SOAP::Transport::HTTP::Client::send_receive: POST http://yyyyy/zzzzz/directory.asmx
Accept: text/xml
Accept: multipart/*
Content-Length: 534
Content-Type: text/xml; charset=utf-8
SOAPAction: http://tempuri.org/GetUIDFromNTLogin

<?xml version="1.0" encoding="UTF-8"?><SOAP-ENV:Envelope xmlns:xsi="http://www.w
3.org/1999/XMLSchema-instance" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/e
ncoding/" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="
http://www.w3.org/1999/XMLSchema" SOAP-ENV:encodingStyle="http://schemas.xmlsoap
.org/soap/encoding/"><SOAP-ENV:Body><namesp1:GetUIDFromNTLogin xmlns:namesp1="ht
tp://tempuri.org"><NTLogin xsi:type="s:string">1234</NTLogin></namesp1:
GetUIDFromNTLogin></SOAP-ENV:Body></SOAP-ENV:Envelope>
LWP::UserAgent::request: ()
LWP::UserAgent::send_request: POST http://yyyyy/zzzzz/directory.asmx
LWP::UserAgent::_need_proxy: Not proxied
LWP::Protocol::http::request: ()
LWP::Protocol::collect: read 441 bytes
LWP::UserAgent::request: Simple response: Internal Server Error
SOAP::Transport::HTTP::Client::send_receive: HTTP::Response=HASH(0x______)
SOAP::Transport::HTTP::Client::send_receive: HTTP/1.1 500 Internal Server Error
Cache-Control: private
Date: Mon, 04 Jun 2012 15:54:47 GMT
Server: Microsoft-IIS/6.0
Content-Length: 441
Content-Type: text/xml; charset=utf-8
Client-Date: Mon, 04 Jun 2012 15:54:47 GMT
Client-Peer: 10.94.61.146:80
Client-Response-Num: 1
Set-Cookie: BIGipServer_____________-http=_________________; path=/
X-AspNet-Version: 2.0.50727
X-Powered-By: ASP.NET

<?xml version="1.0" encoding="utf-8"?><soap:Envelope xmlns:soap="http://schemas.
xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance
" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><soap:Body><soap:Fault><faultcode
>soap:Server</faultcode><faultstring>Server was unable to process request. ---&g
t; Object reference not set to an instance of an object.</faultstring><detail />
</soap:Fault></soap:Body></soap:Envelope>
SOAP::Deserializer::deserialize: ()
SOAP::Parser::decode: ()
SOAP::SOM::new: ()
SOAP::Lite::DESTROY: ()
SOAP::Deserializer::DESTROY: ()
SOAP::Transport::DESTROY: ()
SOAP::Transport::HTTP::Client::DESTROY: ()
SOAP::Serializer::DESTROY: ()
SOAP::Data::DESTROY: ()
SOAP::Data::DESTROY: ()
SOAP::Data::DESTROY: ()
SOAP::Data::DESTROY: ()
SOAP::Data::DESTROY: ()
lets test it...

1
result():
SOAP::SOM::DESTROY: ()
SOAP::Data::DESTROY: ()
SOAP::Parser::DESTROY: ()
SOAP::Transport::DESTROY: ()
SOAP::Serializer::DESTROY: ()
SOAP::Deserializer::DESTROY: ()
SOAP::Lite::DESTROY: ()
Press any key to continue . . .

私が行ったいくつかの調査の結果、エラーはWSサーバー側にあるという印象を受けました。それでも、WSは完全に機能しているように見えるので、Perlスクリプトに何か問題があると思いますが、何がわからないのでしょうか...

どんな助けでも大歓迎です!

ありがとう、

[更新#1]

WSページの例を次に示します。

リクエスト

POST /zzzzz/directory.asmx HTTP/1.1
Host: yyyyy
Content-Type: text/xml; charset=utf-8
Content-Length: length
SOAPAction: "http://xxxxx/GetUIDFromNTLogin"

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
  <soap:Body>
    <GetUIDFromNTLogin xmlns="http://xxxxx/">
      <NTLogin>string</NTLogin>
    </GetUIDFromNTLogin>
  </soap:Body>
</soap:Envelope>

応答

HTTP/1.1 200 OK
Content-Type: text/xml; charset=utf-8
Content-Length: length

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
  <soap:Body>
    <GetUIDFromNTLoginResponse xmlns="http://xxxxx/">
      <GetUIDFromNTLoginResult>string</GetUIDFromNTLoginResult>
    </GetUIDFromNTLoginResponse>
  </soap:Body>
</soap:Envelope>

[アップデート#2]

user1215106が提案した内容の出力は次のとおりです。

<HTML>
<HEAD><TITLE>An Error Occurred</TITLE></HEAD>
<BODY>
<H1>An Error Occurred</H1>
400 Bad Request
</BODY>
</HTML>
4

4 に答える 4

3

以下のコードをテストして、あなたの経験と得られた結果をお知らせください。

#!perl -w 

use strict; 
use warnings;
use LWP::UserAgent; 
use SOAP::Lite

use LWP::Debug; LWP::Debug::level('+'); SOAP::Lite->import(+trace => 'all');

print SOAP::Lite 
  -> uri('http://xxxxx') 
  -> proxy('http://yyyyy/zzzzz/directory.asmx') 
  -> on_action(sub { sprintf '"%s"', shift })
  -> on_fault(sub {
       my($soap, $res) = @_; 
       die ref $res ? $res->faultstring : $soap->transport->status, "\n";
     })
  -> GetUIDFromNTLogin(SOAP::Data->type('string')->name('NTLogin')->value(1234))
  -> result;

[アップデート]

あなたが投稿した情報に基づいてHTTP::Request、 library なしで直接コードを実行することをお勧めしますSOAP::Lite。あなたが持っている正確な情報で以下のコードを変更してください:

#!perl -w          

use strict;          
use warnings;

use LWP::UserAgent;
use HTTP::Request;

my $message = '<SOAP-ENV:Envelope xmlns:xsi="http://www.w3.org/1999/XMLSchema-instance" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/1999/XMLSchema" SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"><SOAP-ENV:Body><namesp1:GetUIDFromNTLogin xmlns:namesp1="http://tempuri.org"><NTLogin xsi:type="s:string">1234</NTLogin></namesp1: GetUIDFromNTLogin></SOAP-ENV:Body></SOAP-ENV:Envelope>';

my $userAgent = LWP::UserAgent->new();
my $request = HTTP::Request->new(POST => 'http://...');
$request->header(SOAPAction => '"http://tempuri.org/GetUIDFromNTLogin"');
$request->content($message);
$request->content_type("text/xml; charset=utf-8");

my $response = $userAgent->request($request);

if ($response->code == 200) {
  print $response->as_string;
}
else {
  print $response->error_as_HTML;
}
于 2012-06-03T19:48:09.323 に答える
1

「サーバーはリクエストを処理できませんでした。オブジェクト参照がオブジェクトのインスタンスに設定されていません」</p>

私が行ったいくつかの調査の結果、エラーはWSサーバー側にあるという印象を受けました。それでも、WSは完全に機能しているように見えるので、Perlスクリプトに何か問題があると思いますが、何がわからないのでしょうか...

これは間違いなくサーバー側のエラーです。これは、おそらく.NETサーバーコードのバグが原因です。System.NullReferenceException簡単に再現できます。

D:\temp :: more nr.cs
class Program {
        static void Main() {
                object o = null;
                string s = o.ToString();
        }
}

D:\temp :: csc /nologo nr.cs

D:\temp :: nr.exe

Unbehandelte Ausnahme: System.NullReferenceException:
Der Objektverweis wurde nicht auf eine Objektinstanz festgelegt.
   bei Program.Main()

これはSOAPクライアントとは何の関係もありませんが、クライアントがエラーメッセージを引き出すことによってバグを公開するだけです。

別の返信へのコメントであなたは書いた:

ちなみに、xxxxxはtempuri.orgです。これは、.NetWSを作成するときのデフォルトのアドレスです。とにかく公式の例で見ることができるものですが、多分これを使うべきではありませんか?

これは大げさな推測ですが、別のディスカッションのユーザーは、ヘッダーNullReferenceExceptionに正しいURLを指定しなかったためにをSOAPAction取得しました。これはあなたがチェックできるものです。SOAPActionヘッダーが何であるかを調べ、それに応じて設定するようにしてください。何が起こっているのかをサーバーにアクセスできる場合は、もちろん、デバッグに役立つでしょう。最終的には、バグは明らかにサーバー側にあるからです。

于 2012-06-05T07:03:17.300 に答える
1

HTTP 500サーバーエラーは、サーバー側のエラーを示していることに同意します。

したがって、最初の呼び出しポートは、WebServiceアプリケーションから完全なデバッグログを取得し、それらをそのWebServiceの開発者/ベンダーに送信することです。これを実装のバグとして報告してください。ここではナンセンスを容認しません。Perlクライアントが不良(または欠落している)データをWebサービスに渡している場合でも、HTTP500サーバーエラーで応答することはありません。それはバグです。エラーメッセージは、欠陥のあるクライアントリクエストの周りに腕を置き、「ああ、ここを見てください。これは何を送ってくれますか?私の素敵なドキュメントで次のように伝えていませんでした。 NTUserはシステム上に存在する必要がありますか?(または問題が何であれ)その要求を再度送信しますが、今回は使用できる実際のデータとともに要求を送信します。」HTTP400の範囲

必要に応じて、これがWebサービスコードの欠陥であるというケースをさらにバックアップするには、SOAPUiを使用してエラーを再現することにより、問題の根本原因であるPerlクライアントを排除します。

その後、Soap UIプロジェクトをWebサービス開発者と共有できます。これにより、開発者はこのバグを簡単に見つけることができます。

于 2012-06-06T01:02:35.473 に答える