gpt4 book ai didi

web-services - Perl/SOAP 精简版 : "Server was unable to process request. Object reference not set to an instance of an object"

转载 作者:行者123 更新时间:2023-12-04 04:57:41 27 4
gpt4 key购买 nike

我正在尝试使用一个已经存在的 Web 服务,并且效果很好。在阅读了许多教程和示例后,我终于设法从服务器上得到了答案:

Server was unable to process request. Object reference not set to an instance of an object



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();

这是输出:
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>

最佳答案

请测试下面的代码,让我们知道您的经验和输出。

#!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代码,无库 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;
}

关于web-services - Perl/SOAP 精简版 : "Server was unable to process request. Object reference not set to an instance of an object",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10752009/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com