Perl/Soap lite:"服务器无法处理请求.对象引用未设置为对象的实例"

Wil*_*l1v 8 perl soap web-services soaplite

我正在尝试使用已经存在且完美运行的Web服务.在阅读了许多教程和示例之后,我终于设法从服务器获得了答案:

服务器无法处理请求.你调用的对象是空的

WS只允许您从NT登录中获取和ID(一个字符串参数,一个字符串答案).

这是我的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();
Run Code Online (Sandbox Code Playgroud)

这是输出:

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 . . .
Run Code Online (Sandbox Code Playgroud)

经过一些研究,我已经得到了错误在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>
Run Code Online (Sandbox Code Playgroud)

响应

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>
Run Code Online (Sandbox Code Playgroud)

[更新#2]

这是user1215106建议的输出:

<HTML>
<HEAD><TITLE>An Error Occurred</TITLE></HEAD>
<BODY>
<H1>An Error Occurred</H1>
400 Bad Request
</BODY>
</HTML>
Run Code Online (Sandbox Code Playgroud)

小智 0

我发现了这个:http://www.perlmonks.org/?node_id =719987

那家伙将这一行添加到他们的代码中:

sub SOAP::Transport::HTTP::Client::get_basic_credentials { 
    return ('user' => 'password') 
};
Run Code Online (Sandbox Code Playgroud)

另外,请使用use strict; 使用警告;

移动顶部的 shebang 行 (#!perl)

启用调试:

use LWP::UserAgent;
use LWP::Debug;
LWP::Debug::level('+');
SOAP::Lite->import(+trace => 'all');
Run Code Online (Sandbox Code Playgroud)

确保您的系统中安装了 LWP::Authen::Ntlm。

目前您收到“HTTP/1.1 500 内部服务器错误”错误。这意味着服务器代码死亡,无法正常工作。它应该向您发送一些有意义的错误消息......

问候,