2

我正在尝试(但失败了)使用 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>

任何人都可以帮忙吗?我已经尝试了几乎所有我能找到的示例,然后尝试了这些示例的变体,但我再也没有设法获得任何进一步的信息。在每种情况下,我都会收到“未授权”退货。

谢谢,

肖恩。

4

2 回答 2

4

不要被误导:SOAP::Lite 的调试输出没有显示 Authorization 标头(出于某种原因?)。

“覆盖 get_basic_credentials”- 方法全局设置用户名/密码,而不考虑域和领域。这实际上是一件坏事......

这段(经过测试的)代码应该可以解决您的问题:

#!/usr/local/perl5/bin/perl -w
use strict;
use SOAP::Lite+trace => 'all';

my $soap = SOAP::Lite->new('proxy' => [
                        'http://<yourdomain>:<yourport>/<yourpath>',
                        'credentials' => [
                                "<yourdomain>:<yourport>",
                                "<yourrealm>",
                                "<yourusername>",
                                "<yourpassword>"
                        ]
                ]);
my $som = $soap->RetrieveList();
die $som->faultstring if ($som->fault);
print $som->result, "\n";

其中“ <yourrealm>”应设置为“CASM”,“ <yourpath>”应设置为“/SM/7/ws”,“ <yourport>”应设置为“13080”。

旧回复:尝试这样做(注意额外的星号):

*SOAP::Transport::HTTP::Client::get_basic_credentials = sub { 
 return ($USER, $PASS);
}
于 2013-02-18T14:52:34.780 回答
0

你找到这个指南了吗?http://www.perl.com/pub/2001/04/24/soap.html#security%20%28ssl,%20basic/digest%20authentication,%20cookiebased%20authentication,%20ticketbased%20authentication,%20access%20control% 29

还是这个答案?将 authHeader 添加到 Perl SOAP::Lite 请求

# create header for requests 
my $authHeader = SOAP::Header->name("xsd:authHeader" => 
\SOAP::Header->value(
    SOAP::Header->name('xsd:user')->value($s7user)->type(''),
    SOAP::Header->name('xsd:password')->value($s7pass)->type(''),
    SOAP::Header->name('xsd:appName')->value('TestApp')->type(''),
    SOAP::Header->name('xsd:appVersion')->value('0.03')->type('')
));

# create data to pass as method paramaters
my $params = SOAP::Data->name('ns:email')->value($s7user)->type('');

# request method
$soap->call('checkLogin', $params, $authHeader);
于 2013-02-18T14:08:47.600 回答