如何在php中创建带有命名空间的Soap Request

时间:2015-11-24 08:49:42

标签: php xml soap namespaces

我正在尝试实现以下肥皂请求,

<soapenv:Envelope 
xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" 
xmlns:tap1="http://www.loclhodd/test/services" 
xmlns:tap2="http://www.loclhodd`enter code here`/test2/services">
   <soapenv:Header/>
   <soapenv:Body>
      <tap1:cusrequest> 
         <tap2:version>1.0.0</tap2:version>
         <tap2:msg>
           <tap2:id>1234566789</tap2:id>
           <tap2:msid>111</tap2:msid> 
         </tap2:msg>             
      </tap1:cusrequest>
   </soapenv:Body>
</soapenv:Envelope>

但我的要求是:

<SOAP-ENV:Envelope SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<SOAP-ENV:Body>
  <cusrequest xsi:type="ns1:msg">
   <msg xsi:type="SOAP-ENC:Struct">
    <id xsi:type="xsd:string">1</id>
    <msid xsi:type="xsd:string">111</msid>
   </msg>
  </cusrequest></appid>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>

我尝试如下,

<?php
  ini_set("soap.wsdl_cache_enabled", 0);
  $client = new SoapClient('http://localhost/test/new_soap/server.php?wsdl', 
                                array('cache_wsdl' => WSDL_CACHE_NONE,
                                      'trace'=>TRUE,
                                      "exceptions" => 1,
                                      'soap_version' => SOAP_1_1
                                     )
                           );

  $tap1 = "http://www.loclhodd/test/services";
  $tap2 = "http://www.loclhodd/test/services";

  $messages = new stdClass();           
  $messages->id = '1';
  $messages->msid = '111'; 

  $custreqType = new stdClass();
  $custreqType->msg = $messages;
  $custreq = new SoapVar($custreqType, SOAP_ENC_OBJECT, "msg", $tap1);

  $soapRequestType = new stdClass();
  $soapRequestType->cusrequest = $custreq;
  $getRateAvailabilityReq = new SoapVar($soapRequestType, SOAP_ENC_OBJECT, "cusrequest", $tap1); 

 try {
    $product = $client->testRequest($getRateAvailabilityReq );
  } catch (SoapFault $e) {
     //print($client->__getLastResponse());
  } 

如何实现预期的请求,我需要在代码库中更新

0 个答案:

没有答案