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.

10
  • 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. Commented Sep 28, 2017 at 21:49
  • You should try to use native php soapclient and see if it helps. You can follow the guide on stackoverflow.com/questions/29934167/… and it should be quite easy to test. Commented Sep 29, 2017 at 0:00
  • You can also see that some users have found issues with nusoap connecting to C#(.Net) stackoverflow.com/questions/15402233/… Commented Sep 29, 2017 at 0: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. Commented Sep 29, 2017 at 3:24
  • This error is often raised when there are communication/network/protocol issues. Have you tried the solutions posted here: link ? Commented Oct 2, 2017 at 10:28

2 Answers 2

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

Sign up to request clarification or add additional context in comments.

6 Comments

I am using php version 5.6. I just try with __soapCall() but same result
@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."\"?
@karim_fci in addition check this post php.net/manual/en/class.soapclient.php#116724 if php version mentioned in that example, exactly matches the one you use.
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"
According to your last comment reference solution getting this error: SoapClient Error "SOAP-ERROR: Parsing WSDL: Couldn't load from 'example.com/example.svc?wsdl' : failed to load external entity "example.com/example.svc?wsdl" "
|
0

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

or this in stackoverflow

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.