1

我想用 Perl 发出一个 SOAP 请求,我想发送原始 XML 数据,例如

$xml = "<IODATA>
  <TEST>
    Hello World
  </TEST>
</IODATA>";

我正在使用这样的 SOAP::Lite:

my $soap = SOAP::Lite->service('http://localhost/cms/WebService/RDCMSXMLServer.WSDL');
$soap->Execute($xml, "", "");

但是当我检查 SOAP 主体时,我的 xml 被解析并且看起来像这样:

&lt;IODATA&gt;

等等

WSDL 文件:

<?xml version='1.0' encoding='UTF-8' ?>
<definitions
name='RDCMSXMLServer'
targetNamespace='http://tempuri.org/RDCMSXMLServer/webservice/'
xmlns:wsdlns='http://tempuri.org/RDCMSXMLServer/webservice/'
xmlns:typens='http://tempuri.org/RDCMSXMLServer/type/'
xmlns:soap='http://schemas.xmlsoap.org/wsdl/soap/'
xmlns:xsd='http://www.w3.org/2001/XMLSchema'
xmlns:stk='http://schemas.microsoft.com/soap-toolkit/wsdl-extension'
xmlns:dime='http://schemas.xmlsoap.org/ws/2002/04/dime/wsdl/'
xmlns:ref='http://schemas.xmlsoap.org/ws/2002/04/reference/'
xmlns:content='http://schemas.xmlsoap.org/ws/2002/04/content-type/'
xmlns:wsdl='http://schemas.xmlsoap.org/wsdl/'
xmlns='http://schemas.xmlsoap.org/wsdl/'>

<types>
    <schema
        targetNamespace='http://tempuri.org/RDCMSXMLServer/type/'
        xmlns='http://www.w3.org/2001/XMLSchema'
        xmlns:SOAP-ENC='http://schemas.xmlsoap.org/soap/encoding/'
        xmlns:wsdl='http://schemas.xmlsoap.org/wsdl/'
        elementFormDefault='qualified'>

        <import namespace='http://schemas.xmlsoap.org/soap/encoding/'/>
        <import namespace='http://schemas.xmlsoap.org/wsdl/'/>
        <import namespace='http://schemas.xmlsoap.org/ws/2002/04/reference/'/>
        <import namespace='http://schemas.xmlsoap.org/ws/2002/04/content-type/'/>

    </schema>
</types>

<message name='XmlServer.Execute'>
    <part name='sParamA' type='xsd:string'/>
    <part name='sErrorA' type='xsd:anyType'/>
    <part name='sResultInfoA' type='xsd:anyType'/>
</message>

<message name='XmlServer.ExecuteResponse'>
    <part name='Result' type='xsd:string'/>
    <part name='sErrorA' type='xsd:anyType'/>
    <part name='sResultInfoA' type='xsd:anyType'/>
</message>

<portType name='XmlServerSoapPort'>

    <operation name='Execute' parameterOrder='sParamA sErrorA sResultInfoA'>
        <input message='wsdlns:XmlServer.Execute'/>
        <output message='wsdlns:XmlServer.ExecuteResponse'/>
    </operation>

</portType>

<binding name='XmlServerSoapBinding' type='wsdlns:XmlServerSoapPort' >

    <stk:binding preferredEncoding='UTF-8'/>
    <soap:binding style='rpc' transport='http://schemas.xmlsoap.org/soap/http'/>

    <operation name='Execute'>
        <soap:operation soapAction='http://tempuri.org/RDCMSXMLServer/action/XmlServer.Execute'/>
        <input>
            <soap:body
                use='encoded'
                namespace='http://tempuri.org/RDCMSXMLServer/message/'
                encodingStyle='http://schemas.xmlsoap.org/soap/encoding/'
                parts='sParamA sErrorA sResultInfoA'/>
        </input>
        <output>
            <soap:body
                use='encoded'
                namespace='http://tempuri.org/RDCMSXMLServer/message/'
                encodingStyle='http://schemas.xmlsoap.org/soap/encoding/'
                parts='Result sErrorA sResultInfoA'/>
        </output>
    </operation>

</binding>

<service name='RDCMSXMLServer' >
    <port name='XmlServerSoapPort' binding='wsdlns:XmlServerSoapBinding' >
        <soap:address location='http://10.1.102.104:80/CMS/webservice/RDCMSXMLServer.WSDL'/>
    </port>
</service>

 </definitions>

我该如何改变呢?

非常感谢您提前。

克里斯

4

1 回答 1

3

我想用 Perl 发出一个 SOAP 请求,我想发送原始 XML 数据

让我们来看看。在SOAP::Data 文档中有一个关于使用原始 XML 的部分。这里是:

在某些情况下,您可能需要使用原始的未序列化 XML 文本对消息进行编码。要使用原始 XML 实例化 SOAP::Data 对象,请执行以下操作:

$xml_content = "<foo><bar>123</bar></foo>";
$elem = SOAP::Data->type('xml' => $xml_content);

您也可以使用您的代码执行此操作。它可能看起来像这样:

my $xml = <<'XML';
<IODATA>
  <TEST>
    Hello World
  </TEST>
</IODATA>
XML

my $soap = SOAP::Lite->service('http://localhost/cms/WebService/RDCMSXMLServer.WSDL');
my $res = $soap->sayHello(SOAP::Data->type( 'xml' => $xml ));

但是,这将不起作用,因为sayHello您的 WSDL 文件中没有定义名为的方法!我没有尝试过您的 WSDL,但您可能想再次通读SOAP::Lite 文档以自己完成此操作。

我相信它可以像这样或类似的方式工作(未经测试!):

use SOAP::Lite;
my $soap = SOAP::Lite->service("http://localhost/cms/WebService/RDCMSXMLServer.WSDL");
my $result = $soap->Execute($sParamA, $sErrorA,$ sResultInfoA);
print $result->result();

您可能还会发现很有帮助。

于 2012-10-16T15:08:03.307 回答