2

Here are my request details

$output='<xml version="1.0" encoding="utf-16"?>  
 <opertaion xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">    
 <foo xmlns="http://www.w3schools.com">12</foo>    
<boo xmlns="http://www.w3schools.com">15</boo>   
 <bar xmlns="http://www.w3schools.com">test value</bar>   
 </opertaion>';


 $url='http://www.url.com';
    $headers = array(
                    "Content-type: text/xml;charset=\"utf-8\"",
                    "Accept: text/xml",
                    "Cache-Control: no-cache",
                    "Pragma: no-cache",
                    "Content-length: ".strlen($output),
                ); //SOAPAction: your op URL
        // PHP cURL  for https connection with auth
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
        curl_setopt($ch, CURLOPT_TIMEOUT, 10);
        curl_setopt($ch, CURLOPT_POST, true);
         curl_setopt($ch, CURLOPT_USERPWD, $soapUser.":".$soapPassword);
        curl_setopt($ch, CURLOPT_POSTFIELDS, $output); // the SOAP request
        curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);

        // converting
        $response = curl_exec($ch); 
        curl_close($ch);

       echo $response;

soap:VersionMismatchSystem.Web.Services.Protocols.SoapException: Possible SOAP version mismatch: Envelope namespace was unexpected. Expecting http://schemas.xmlsoap.org/soap/envelope/. at System.

What is the error I'm doing?

abarisone
  • 3,429
  • 11
  • 27
  • 49
vellai durai
  • 933
  • 3
  • 11
  • 28
  • Could you please add more information about your error? And I can see that your output XML contains an `` tag instead of `` – abarisone Jun 08 '16 at 12:41

1 Answers1

2

If you want to make a SOAP call using cURL, you need to make yourself sure that your request body is a correct SOAP request.

Your XML needs to be wrapped with SOAP tags, like this:

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
  <soap:Body>
    <opertaion xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">    
      <foo xmlns="http://www.w3schools.com">12</foo>    
      <boo xmlns="http://www.w3schools.com">15</boo>   
      <bar xmlns="http://www.w3schools.com">test value</bar>   
    </opertaion>
  </soap:Body>
</soap:Envelope>

You can also use SoapClient: http://php.net/manual/en/soapclient.soapclient.php

Marcin O
  • 204
  • 1
  • 4
  • is it necessary to give SOAPAction? – vellai durai Jun 08 '16 at 12:55
  • Yes, because SOAP url (the url you're making a request to) is just URL to a service, which contains actions. You need to specify action in your header, check this answer: http://stackoverflow.com/a/7157785/4405882 – Marcin O Jun 09 '16 at 07:33