How to create a Soap request with namespace in php

I am trying to reach below the soap request,

<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>

But I ask:

<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>

and I tried as shown below

<?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());
  } 

How can I achieve the expected request that I need to update in the codebase

+4
source share

Source: https://habr.com/ru/post/1617201/


All Articles