xml - 带有 XML::Compile::SOAP::WSS 和 Perl 的 WSSE

标签 xml perl soap

因此,我在向 SOAP 请求添加 wsse header 时遇到了一些问题。

#!/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

早些时候我尝试过我的 $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 header ?

更新

我可以生成这个 SOAP

<?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 等于我尝试的任何标签。

最佳答案

我已向发行版添加了示例,以展示如何执行此操作。另外,我添加了一个方法来帮助您生成这种特定的登录方式。发布为XML-Compile-WSS版本0.12 .

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

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

关于xml - 带有 XML::Compile::SOAP::WSS 和 Perl 的 WSSE,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7128316/

相关文章:

php - 我是否需要 PHP 为 RSS/ATOM 提供具有正确内容类型的 HTTP header ?

linux - 如何仅从文件中删除最后一个单词

php - Magento Soap API 添加捆绑产品到购物车

python - 将 xml 文件解析为 csv 时跳过空元素

regex - 匹配包含特定词的 URL

c# - 遵循 LINQ-to-XML 哲学,从生成的 XML 文档中省略可选属性

perl - 我如何比较 Perl 中的 md5 校验和?

perl - 奇怪的行为

wcf - 使用 .Net Core 3.1 签署 Soap 1.1 主体

c# - ASMX Web 服务能否在特定条件下返回空白的 XML 文档?