我正在尝试(但失败了)使用 SOAP::LITE 编写一个简单的测试应用程序来访问 HP Service Manager 站点。(我也尝试过 SOAP::WSDL,但进一步阅读让我相信它确实不是我想做的事情所必需的。)
我是 SOAP 的新手,这些包的新手,以及我正在尝试做的事情的新手,所以我不知道我做错了多少事情,但我想我已经把它提炼成几个在我看来应该可以工作的代码行。我认为基本问题在于身份验证,但我也考虑过这可能是我试图通过 SOAP 调用服务管理器例程的方式。
这是我找到的第一种方法:
#!/usr/local/perl5/bin/perl
use SOAP::Lite+trace => 'all';
$USER = "working_user_name";
$PASS = "working_password";
sub SOAP::Transport::HTTP::Client::get_basic_credentials {
print "###\n";
print "###\n";
print "### Authenticating...\n";
print "###\n";
print "###\n";
return $USER => $PASS;
}
my $soap = SOAP::Lite->new(proxy => 'http://<hp_service_manager>:13080/SM/7/ws');
$soap->default_ns('http://schemas.hp.com/SM/7');
my $som = $soap->call('RetrieveList');
die $som->faultstring if ($som->fault);
print $som->result, "\n";
而我尝试的 LWP 方法:
#!/usr/local/perl5/bin/perl
use SOAP::Lite+trace => 'all';
use LWP::UserAgent;
use LWP::Debug;
LWP::Debug::level('+');
$USER = "working_user_name";
$PASS = "working_password";
my @ua_args = (keep_alive => 1);
my @credentials = ($SERVICE_NS, "", $USER, $PASS);
my $schema_ua = LWP::UserAgent->new(@ua_args);
$schema_ua->credentials(@credentials);
my $soap = SOAP::Lite->new(proxy => 'http://<hp_service_manager>:13080/SM/7/ws', @ua_args, credentials => \@credentials);
$soap->default_ns('http://schemas.hp.com/SM/7');
my $som = $soap->call('RetrieveList');
die $som->faultstring if ($som->fault);
print $som->result, "\n";
问题是,无论我做什么,我都会得到“未经授权”的退货。这是一个 HP Service Manager 安装。我将为我正在尝试做的事情提供 WSDL 条目。我怀疑它是否有用。
<soap:operation soapAction="RetrieveList" style="document"/>
<input>
<soap:body use="literal"/>
</input>
<output>
<soap:body use="literal"/>
</output>
</operation>
虽然还有更多的来源,但这是相关的输出,我相信:
SOAP::Transport::HTTP::Client::send_receive: HTTP::Request=HASH(0x845c630)
SOAP::Transport::HTTP::Client::send_receive: POST http://<service_manager>:13080/SM/7/ws HTTP/1.1
Accept: text/xml
Accept: multipart/*
Content-Length: 488
Content-Type: text/xml; charset=utf-8
SOAPAction: "#default_ns"
<?xml version="1.0" encoding="UTF-8"?><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><default_ns><c-gensym3 xsi:type="xsd:string">http://schemas.hp.com/SM/7</c-gensym3></default_ns></SOAP-ENV:Body></SOAP-ENV:Envelope>
SOAP::Transport::HTTP::Client::send_receive: HTTP::Response=HASH(0x8597238)
SOAP::Transport::HTTP::Client::send_receive: HTTP/1.1 401 Unauthorized
Connection: close
Date: Fri, 15 Feb 2013 19:42:06 GMT
Server: Apache-Coyote/1.1
WWW-Authenticate: Basic realm="CASM"
Content-Length: 40
Content-Type: text/html;charset=utf-8
Client-Date: Fri, 15 Feb 2013 19:42:07 GMT
Client-Peer: nnn.nn.nn.nn:13080
Client-Response-Num: 1
<HTML><BODY>Not Authorized</BODY></HTML>
任何人都可以帮忙吗?我已经尝试了几乎所有我能找到的示例,然后尝试了这些示例的变体,但我再也没有设法获得任何进一步的信息。在每种情况下,我都会收到“未授权”退货。
谢谢,
肖恩。