我正在嘗試 - 並且失敗 - 使用SOAP :: LITE來編寫一個簡單的測試應用程序來訪問HP Service Manager站點。 (我也嘗試SOAP :: WSDL,但進一步的閱讀讓我相信它真的不需要什麼,我想做的事情。)Perl SOAP :: LITE - 無法驗證?
我是新來的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>
誰能幫助?我已經嘗試了幾乎所有我能夠找到的示例,然後嘗試了這些示例的變體,並且我從未設法獲得任何進一步信息。在任何情況下,我都會收到「未經授權」的退貨。
謝謝,
肖恩。
你能成功地驗證手動使用了SoapUI?每當我在處理SOAP/WSDL時都有疑問時,我會使用[SoapUI](http://www.soapui.org/About-SoapUI/what-is-soapui.html)。 – slayedbylucifer 2013-02-18 13:37:20