perl – 如何在SOAP :: Lite中破坏名称空间生成?

前端之家收集整理的这篇文章主要介绍了perl – 如何在SOAP :: Lite中破坏名称空间生成?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
场景:

>客户端是使用SOAP::Lite的Perl脚本.
>服务器是使用Spring和CXF的基于Java的应用程序.

我的客户端基于WSDL生成以下SOAP请求:

<?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:Body>
        <createFolder xmlns="http://xyz.com/">
            <parentId xsi:type="xsd:string">1</parentId>
            <folderName xsi:type="xsd:string">Test</folderName>
        </createFolder>
    </soap:Body>
</soap:Envelope>

此请求将对CXF失败.经过多次调查后,我发现以下手动生成的请求将起作用:

<?xml version="1.0" encoding="UTF-8"?>
<soap:Envelope xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xyz="http://xyz.com/">
    <soap:Body>
        <xyz:createFolder>
            <parentId xsi:type="xsd:string">1</parentId>
            <folderName xsi:type="xsd:string">Test</folderName>
        </xyz:createFolder>
    </soap:Body>
</soap:Envelope>

不同之处在于元素createFolder的名称空间定义.

我的问题是:如何配置SOAPLite来创建有效的SOAP请求?

反之亦然:如何将CXF配置为接受SOAP :: Lite请求样式?

解决方法

查看 ns.如果为片段的根元素提供了类似的限定名称

使用以下内容

SOAP::Lite->new->proxy( 'http://somewhere.com' )
    ->ns( 'http://xyz.com/','xyz' )->createFolder( 
      SOAP::Data->new( name => 'parentId',value => 1,type => 'xsd:string' ),SOAP::Data->new( name => 'folderName',value => 'Test' ) 
    );

我得到以下内容

<?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:xyz="http://xyz.com/" 
    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:Body>
    <xyz:createFolder>
      <parentId   xsi:type="xsd:string">1</parentId>
      <folderName xsi:type="xsd:string">Test</folderName>
    </xyz:createFolder>
  </soap:Body>
</soap:Envelope>

而且我认为这就是你想要的.

猜你在找的Perl相关文章