使用__soapcall()PHP的邮件正文的SOAP请求格式不正确

时间:2016-06-24 06:21:54

标签: php soap request format

我使用__soapcall()发送肥皂请求。

     $parameters = array(
        'ID' => '0001',
        'TimeStamp' => '2016-06-20T17:03:27Z',
        'SenderID' => 'B2eww8',

    );

    $URL = 'https://example.com';

    $client = new \SoapClient(null, array(
        'location' => $URL,
        'uri' => "http://example.com/SOAP/WSDL/abc.xsd",
        'trace' => 1

    ));

     $return = $client->__soapCall("TestSoapRequest", $parameters);

   var_dump($return);

然后请求看起来像。

<SOAP-ENV:Body>
    <ns1:TestSoapRequest>
        <param0 xsi:type="xsd:string">0001</param2>
        <param1 xsi:type="xsd:string">2016-06-20T17:03:27Z</param3>
        <param2 xsi:type="xsd:string">B2eww8</param4>
     </ns1:TestSoapRequest>
</SOAP-ENV:Body>

但希望的格式是,

<soapenv:Body>
    <ns1:TestSoapRequest xmlns:ns1="http://www.caqh.org/SOAP/WSDL/CORERule2.2.0.xsd">
        <ID>0001</ID>
        <TimeStamp>2014-05-22T17:03:27Z</TimeStamp>
        <SenderID>B2eww8</SenderID>
        </ns1:TestSoapRequest>
</soapenv:Body>

我怎么能做到这一点。

2 个答案:

答案 0 :(得分:0)

http://www.caqh.org/SOAP/WSDL/CORERule2.2.0.xsd中没有TestSoapRequest的定义,因此如果您想在没有它的情况下准备请求,那么您应该使用此处所述的SoapParamhttp://php.net/manual/en/soapparam.soapparam.php

这里已经描述了类似的问题PHP Soap non-WSDL call: how do you pass parameters?

答案 1 :(得分:0)

几个月前,我遇到了同样的问题,当时我正在使用 XML 文档。我创建了一个生成器文件,该文件创建了一个结构更正的 XML 文档。

    $XMLDocument = new DOMDocument('1.0', 'UTF-8');
    $Body = $XMLDocument->createElement('soapenv:Body', null);
    $Body->setAttributeNS('http://www.w3.org/2000/xmlns/', 'xmlns:ns1', "http://www.caqh.org/SOAP/WSDL/CORERule2.2.0.xsd");

    $TestSoapRequest = $XMLDocument->createElement('TestSoapRequest', null);

    $element = $XMLDocument->createElement('ID', '0001');
    $TestSoapRequest->appendChild($grossWeightElement);
    
    $element = $XMLDocument->createElement('TimeStamp', '2014-05-22T17:03:27Z');
    $TestSoapRequest->appendChild($grossWeightElement);
    
    $element = $XMLDocument->createElement('SenderID', 'B2eww8');
    $TestSoapRequest->appendChild($grossWeightElement);