PHP Soap Client - sending the wrong headers “soape

2019-08-04 09:28发布

问题:

I've come across a problem that I cannot figure out how to fix. I've created a soap client in php that is supposed to do an xml request to a web service - the service is working through SoapUI, but whenever I send the same request through my php client I get the following faultcode:

<?xml version="1.0" encoding="utf-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
  <soapenv:Body>
    <soapenv:Fault>
      <faultcode>**soapenv:VersionMismatch**</faultcode>
      <faultstring>**Transport level information does not match with SOAP Message namespace URI**</faultstring>
      <detail></detail>
    </soapenv:Fault>
  </soapenv:Body>
</soapenv:Envelope>

Now, both the client and the service are working with soap version 1.2, I believe that the problem is in the client, so here it is how I've defined it:

$options  = array(
    'trace'        => true, 
    'exceptions'   => 1, 
    'style'        => SOAP_DOCUMENT,
    'use'          => SOAP_LITERAL,
    'soap_version' => SOAP_1_2,
);
$client = new SoapClient("location_of_the_wsdl", $options);

In the request I'm using the following code:

<env:Envelope xmlns:env="http://www.w3.org/2003/05/soap-envelope" xmlns:soapenc="http://www.w3.org/2003/05/soap-encoding" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
   <env:Header/>
   <env:Body>
      <ns2:FunctionName xmlns:ns2="namespace_of_the_service">
         <arg0>
              <data1>?</data1>
           </arg0>
       </ns2:FunctionName>
   </env:Body>
</env:Envelope>

In soapUI this is giving me a 'false' result as the data1 is left with ?, when I write in valid data it returns true.

I've also noticed that in soapUI I'm sending and receiving the Content-type application/soap+xml, but when I'm doing it through the PHP client I send and receive headers with Content-Type text/xml;

What could be the problem? I use nusoap.php for the client.

回答1:

Make sure the WSDL caching feature is disabled in php.ini file of your development (test) machine by setting

soap.wsdl_cache_enabled=0 

I got stocked in this problem for more than 1 day only because of cached WSDL :)



回答2:

You are using SOAP version 1.2 to make your calls. Can you check if the version used by the web service is indeed 1.2 and not 1.1.