1

I need to consume a web service https://www.example.com/example.svc?wsdl in PHP. For this purpose, I am using PHP SOAP client. The code snippet like below:

$client = new SoapClient("https://www.example.com/example.svc?wsdl",
    array('soap_version' => SOAP_1_2,
        'location'=>'https://www.example.com/example.svc',
        'login'=> '#####',
        'password'=> '#######',
        'exceptions'=>true,
        'trace'=>1,
        'cache_wsdl'=>WSDL_CACHE_NONE,
        'encoding'=>'UTF-8',
        'connection_timeout' => 500,
        'keep_alive' =>false));

$client->__call('getProductList',array());

However, when I run this its through following error:

Warning: SoapClient::__doRequest(): SSL: The operation completed successfully. in E:\location\test1.php on line 37

Fatal error: Uncaught SoapFault exception: [HTTP] Error Fetching http headers in E:\location\test1:37 Stack trace: #0 [internal function]: SoapClient->__doRequest('<?xml version="...', 'https://travius...', 'Travius/ITraviu...', 2, 0) #1 E:\location\test1(37): SoapClient->__call('getProductList', Array) #2 {main} thrown in E:\location\test1.php on line 37

I am struggling several days to solve the error but can't figure out. I tried the different solution in stack overflow like 'keep_alive' =>false, connection_timeout but nothing works.

I also try with php nusoap library. its request and response are like following:

Error

HTTP Error: Unsupported HTTP response status 400 Bad Request (soapclient->response has contents of the response)

Request

POST /#####.svc?wsdl HTTP/1.0
Host: #####.#####.eu
User-Agent: NuSOAP/0.9.5 (1.123)
Content-Type: application/soap+xml;charset=UTF-8; charset=UTF-8
SOAPAction: ""
Authorization: Basic RGVtb2FwaTpEdXE1dmRWdA==
Content-Length: 529

<?xml version="1.0" encoding="UTF-8"?><SOAP-ENV:Envelope SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:SOAP-ENV="http://www.w3.org/2003/05/soap-envelope" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/"><SOAP-ENV:Body><GetProduct><parameters><intProductID xsi:type="xsd:int">1266</intProductID><lang xsi:type="xsd:string">CN</lang></parameters></GetProduct></SOAP-ENV:Body></SOAP-ENV:Envelope>

Response

HTTP/1.1 400 Bad Request
Server: Microsoft-IIS/7.5
X-Powered-By: ASP.NET
Date: Mon, 02 Oct 2017 16:03:04 GMT
Content-Length: 0

Please note that this web service works fine in .Net application. Any help highly appreciated. Thanks in advance.

karim_fci
  • 1,212
  • 2
  • 17
  • 36
  • 1
    Please elaborate on where "MySoapClient" came from and an actual WSDL that throws this error. Based on the error, it looks like you're using nusoap, which works fine in general. – jwriteclub Sep 28 '17 at 21:49
  • You should try to use native php soapclient and see if it helps. You can follow the guide on https://stackoverflow.com/questions/29934167/set-up-php-soap-extension-in-windows and it should be quite easy to test. – Kamal Soni Sep 29 '17 at 00:00
  • You can also see that some users have found issues with nusoap connecting to C#(.Net) https://stackoverflow.com/questions/15402233/which-is-better-php-soap-or-nusoap#comment54533941_15402304 – Kamal Soni Sep 29 '17 at 00:14
  • 1
    Have you tried loading the WSDL into a tool like SOAPUI? I would also ask the .Net developer if the contract is compatible with clients outside of .Net. Its very easy to write a WCF service that is only consumable from .Net. – Blast_dan Sep 29 '17 at 03:24
  • This error is often raised when there are communication/network/protocol issues. Have you tried the solutions posted here: [link](https://stackoverflow.com/questions/9403486/error-fetching-http-headers-in-soapclient) ? – Yosh Oct 02 '17 at 10:28
  • I already tried that solution but same results. – karim_fci Oct 02 '17 at 13:50
  • A 400 bad request means that the request is missing something which is expected server side, may be you are not passing all the correct parameters? Is this is a public facing WSDL one can test or your internal? – Tarun Lalwani Oct 02 '17 at 15:53
  • You can check this from here: https://traviusws.travius.eu/TraviusWS.svc – karim_fci Oct 02 '17 at 16:12
  • http://php.net/manual/en/soapclient.soapclient.php "For HTTPS client certificate authentication use local_cert and passphrase options. An authentication may be supplied in the authentication option. The authentication method may be either SOAP_AUTHENTICATION_BASIC (default) or SOAP_AUTHENTICATION_DIGEST." – E_p Oct 02 '17 at 17:56
  • Your URL is not a valid SoapServer. It is a test/example URL only. – Brian from state farm Oct 03 '17 at 19:57

2 Answers2

1

Judging from the error that you posted in your question please change the following line.

$client->__call('getProductList',array());

with something like this

$client = false;
try {
$client = new SoapClient("https://www.example.com/example.svc?wsdl",
    array('soap_version' => SOAP_1_2,
        'location'=>'https://www.example.com/example.svc',
        'login'=> '#####',
        'password'=> '#######',
        'exceptions'=>true,
        'trace'=>1,
        'cache_wsdl'=>WSDL_CACHE_NONE,
        'encoding'=>'UTF-8',
        'connection_timeout' => 500,
        'keep_alive' =>false));
} catch (Exception $e) {
    exit("SoapClient Error \"".$e->getMessage()."\"");
}
if(!empty($client)) {
try {
        $soapResponse = $client->__soapCall('getProductList',array());
        var_dump($soapResponse);
    }  catch (SoapFault $e) { 
        exit("Error using method \"getProductList\" having errorCode \"".$e->faultcode."\"");
    }
}

I don't know what php version you use (you have not posted relevant information) but i think in your case _call is deprecated.

Calling this method directly is deprecated. Usually, SOAP functions can be called as methods of the SoapClient object; in situations where this is not possible or additional options are needed, use SoapClient::__soapCall().

  • 1
    I am using php version 5.6. I just try with __soapCall() but same result – karim_fci Oct 05 '17 at 15:30
  • @karim_fci what does same result mean? The whole snippet is wrapped up inside a try-catch block so is the script exiting with the message `Error using method \"getProductList\" having errorCode \"".$e->faultcode."\"`? –  Oct 06 '17 at 13:34
  • @karim_fci in addition check this post http://php.net/manual/en/class.soapclient.php#116724 if php version mentioned in that example, exactly matches the one you use. –  Oct 06 '17 at 13:56
  • Implementing your solution getting following error: Warning: SoapClient::__doRequest(): SSL: The operation completed successfully. in E:\location.php on line 48 Error using method "getProductList" having errorCode "HTTP" – karim_fci Oct 07 '17 at 03:54
  • According to your last comment reference solution getting this error: SoapClient Error "SOAP-ERROR: Parsing WSDL: Couldn't load from 'https://example.com/example.svc?wsdl' : failed to load external entity "https://example.com/example.svc?wsdl" " – karim_fci Oct 07 '17 at 03:56
  • @karim_fci since you get a 400 error the problem is in the request. I hope you don't use `example.com` as your actual url :). You have to check if method `getProductList` has parameters that have to be passed during the request. Do check if the `SoapClient` parameters cause a problem by starting with something more light e.g. `$client = new SoapClient("https://www.example.com/example.svc?wsdl",array('soap_version' => SOAP_1_2, 'login'=> '#####','password'=> '#######'));` If this is a specific web service of a vendor company then ask them for further details on method requests. –  Oct 07 '17 at 10:19
0

Hi Did you try to write your soap header as wssecurity you can see samples

or this in stackoverflow

Ferhat BAŞ
  • 797
  • 7
  • 12