Thursday, October 5, 2017

PHP SOAP Clients http headers Error

Leave a Comment

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.

2 Answers

Answers 1

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

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

with this

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().

Answers 2

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

or this in stackoverflow

If You Enjoyed This, Take 5 Seconds To Share It

0 comments:

Post a Comment