2011-08-19 23 views
2

所以我在添加wsse頭到我的SOAP請求時遇到一些問題。帶XML ::編譯:: SOAP :: WSS和Perl的WSSE

#!/usr/bin/perl 
use 5.010; 
use strict; 
use warnings; 
use Env qw(CYBS_ID CYBS_KEY); 
use XML::Compile::Util qw(pack_type); 
use XML::Compile::WSDL11; 
use XML::Compile::SOAP::WSS; 
use XML::Compile::SOAP11; 
use XML::Compile::Transport::SOAPHTTP; 

my $soap = XML::Compile::SOAP11::Client->new; 

my $wsdl = XML::Compile::WSDL11->new(
    'CyberSourceTransaction_1.62.wsdl' 
); 

$wsdl->importDefinitions('CyberSourceTransaction_1.62.xsd'); 

my $call = $wsdl->compileClient(operation => 'runTransaction'); 

my ($answer, $trace) = $call->(
    wsse_Security => { 
     version => '1.1', 
     schema => { 
      Username => $CYBS_ID, 
     } 
    }, 
    merchantID   => $CYBS_ID, 
    merchantReferenceCode => '42', 
); 

say $trace->printRequest; 

這裏的輸出我得到

mistake: tag `wsse_Security' not used at {urn:schemas-cybersource-com:transaction-data-1.62}requestMessage 
warning: Internal Server Error 
Request: 
    POST https://ics2wstest.ic3.com/commerce/1.x/transactionProcessor HTTP/1.1 
    User-Agent: libwww-perl/6.02 
    Content-Length: 381 
    Content-Type: text/xml; charset="utf-8" 
    SOAPAction: "runTransaction" 
    X-LWP-Version: 6.02 
    X-XML-Compile-Cache-Version: 0.991 
    X-XML-Compile-SOAP-Version: 2.24 
    X-XML-Compile-Version: 1.22 
    X-XML-LibXML-Version: 1.84 

和生成的XML

<?xml version="1.0" encoding="UTF-8"?> 
    <SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"><SOAP-ENV:Body><data:requestMessage xmlns:data="urn:schemas-cybersource-com:transaction-data-1.62"><data:merchantID>obfuscated</data:merchantID><data:merchantReferenceCode>42</data:merchantReferenceCode></data:requestMessage></SOAP-ENV:Body></SOAP-ENV:Envelope> 

回報?

1 

早些時候我試過my $wss ...代碼......但那也沒用。

下面是實際的請求,我想產生

<?xml version="1.0" encoding="UTF-8"?> 
<soap:Envelope 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" 
    xmlns:xsd="http://www.w3.org/2001/XMLSchema" 
    soap:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" 
    xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"> 
    <soap:Header> 
    <wsse:Security xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd"> 
     <wsse:UsernameToken> 
     <wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">obfuscated</wsse:Password> 

     <wsse:Username>obfuscated</wsse:Username> 
     </wsse:UsernameToken> 
    </wsse:Security> 
    </soap:Header> 

    <soap:Body> 
    <requestMessage xmlns="urn:schemas-cybersource-com:transaction-data-1.61"> 
     <merchantID>obfuscated</merchantID> 

     <merchantReferenceCode>404</merchantReferenceCode> 
    </requestMessage> 
    </soap:Body> 
</soap:Envelope> 

也許有人已經有些想法,怎麼我會被添加WSSE頭?

更新

我能得到這個肥皂產生

<?xml version="1.0" encoding="UTF-8"?> 
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"><SOAP-ENV:Header><wsse:Security xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd"/></SOAP-ENV:Header> 

但一切我試圖把在wsse_Security導致了這樣的錯誤:

mistake: tag `foo' not used at {http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd}Security 

哪裏foo等於我嘗試的任何標籤。

+1

最後更新:肥皂信封標籤未關閉。 – Wivani

+0

@Wivani哦,是啊..這只是從我身上修剪掉身體......因爲它理論上應該與我試圖在標題中做的事無關。 – xenoterracide

+0

只需檢查:您要生成的_request_ ..您是否嘗試過在SoapUI這樣的客戶端中使用它? – Wivani

回答

6

我已經在發行版中添加了示例,以說明如何執行此操作。此外,我添加了一種方法,可以幫助您生成這種特定的登錄方式。發佈爲XML-Compile-WSS版本0.12

my $call  = $wsdl->compileClient($operation); 
my $security = $wss->wsseBasicAuth($username, $password); 

my ($answer, $trace) = $call-> 
(wsse_Security => $security 
, %payload 
); 
+0

請注意,$ wss對象必須使用'(...,schema => $ wsdl)'或$ wss-> loadSchemas($ wsdl)'構造,必須在調用'wsseBasicAuth'之前調用。 – Ether

+0

就我而言,我發現以下鏈接中的示例最有用:https://metacpan.org/pod/XML::Compile::SOAP::WSS – user1027562