UserProg
UserProg

Reputation: 639

PHP Make SOAP Client Request Returns 500 Internal Server Error

I'm using PHP to make SOAP request. I do have information of the web service from the third party. Basically what they have give me:

  1. The full URI request ( http://xx.xx.xx.xx:xxxxxx/some/services/BasicDo )
  2. Username & Password

I am pretty new however I could understand a bit how PHP SOAP things work. However in the example I found the URL called is something like http://xx.xx.xx.xx/services/myservice?wsdl which is not really same with what I have with me. Additional question here is what should I ask them? Perhaps what is the name of wsdl file?

Also so far I have this code with me:

try{
    $client = new SoapClient("http://xx.xx.xx.xx:xxxxx/some/services/BasicDo?wsdl", array('login'=>"myusername",'password'=> "mypwd"));
}
catch(SoapFault $fault) {
    trigger_error("SOAP Fault: (faultcode: {$fault->faultcode}, faultstring: {$fault->faultstring})", E_USER_ERROR);
}

But from the console, I received status 500 Internal Server Error. I don't know how this can be, I am expecting something from the catch block. Somebody please clarify me this. Thank you in advance.

Upvotes: 0

Views: 16252

Answers (5)

KaKa
KaKa

Reputation: 559

Add these codes at head of the file to see where the error happen

ini_set('display_errors','1');
error_reporting(E_ALL);

Upvotes: 2

UserProg
UserProg

Reputation: 639

I really appreciate all of the answers given. I am actually working with another party which I don't have any access on the remote side. My job is to make SOAP request to the server. However it turned out that there is NO web service available for me. So I ended up using cURL to send raw POST of SOAP request. :-)

Upvotes: 0

Arcanyx
Arcanyx

Reputation: 870

I am not sure what the issue may be but I did the following to debug this issue when I encountered it

$client = new SoapClient("http://xx.xx.xx.xx:xxxxx/some/services/BasicDo?wsdl", array('login'=>"myusername",'password'=> "mypwd"));

Things you can do:

  1. Create a PHP file. Name it anything. Write the following code there:

    ini_set('display_errors','On');

    $client = new SoapClient("http://xx.xx.xx.xx:xxxxx/some/services/BasicDo?wsdl", array('login'=>"myusername",'password'=> "mypwd")); var_dump($client); exit;

  2. Run the file.

  3. Chances are this will show you the required exception.

In my case, Our server used a proxy which I had not passed in the parameters due to which I was getting the issue. Let us know how it goes.

Thanks

Upvotes: 1

Drakes
Drakes

Reputation: 23660

Unfortunately, it seems like no matter what you try (e.g. passing array('exceptions' => 0), SoapClient() will throw an uncatchable E_ERROR on network connection issues. This bug is still present as high up as PHP 5.5.4 (REF).

Summary:

Test script:

$client=@new SoapClient('garbage',array('exceptions'=>FALSE));
echo 'OK';

Expected result: We should see "OK",

Actual result:

If we use register_shutdown_function to display the contents of error_get_last(), we get:

Array
(
    [type] => 1
    [message] => SOAP-ERROR: Parsing WSDL: Couldn't load from 'garbage' : failed 
to load external entity "garbage"
)

To explain why you suddenly get this error without changing anything on your system, and to explain why SoapClient works on your local machine and not on your production system, it is most likely a firewall issue.

Here is what another person reported that solved his problem:

I solved my problem. It was actually an issue with my firewall. The firewall was dropping packets sent via PHP, but via curl or wget were not being dropped. I added a rule for all traffic from that server and increased the packet drop length and everything is working great now!

Advice:

My best advice at this time to write some code in the same PHP file that checks if the SOAP service url resolves and loads properly before calling the SoapClient.

Upvotes: 5

A squared
A squared

Reputation: 131

First you need to make sure you have access to the SOAP server.

From the machine that is running your php script try to access the wsdl file and check if it is valid.

you can for example use wget http://xx.xx.xx.xx:xxxxx/some/services/BasicDo?wsdl then open the saved file and see what you are getting. Is it a valid wsdl?

Once you have sorted out our access, then you need to read the documentation here and here. You may need to authenticate differently or pass other options.

As for why the catch block is not picking up your exception, you are only catching SoapFault. The 500 internal server error can be caused by anything.

Upvotes: 0

Related Questions