5

I am trying to connect to an API using PHP and its built-in SoapClient. I have checked against the url I was given through the ill-formatted documents the client gave and $client->__getFunctions() returns a list of three functions. HelloWorld($name), which responds with Hello ~name~, shows me that I am communicating with the server through the SoapClient call and the URL is correct.

However, when I try to access one of the other methods that __getFunctions() gives me, even after copy/pasting the XML from the docs and putting in my own credentials, I am still being given an Internal Server Error faultstring and 500 as faultcode from the SoapFault object.

I am sure that it is my own XML string that is causing the issue but I cannot for the life of me figure out how. Reaching out to the API provider directly hasn't proven helpful. This is my first time dealing with Soap/Web Services so I am unsure of where to go from here.

I did wget http//xxx.xxx.xxx?wsdl and it returned me what looks like a valid XML response, the same one I get when I go directly to the url in the browser. What should I be looking into in order to solve this issue? All of the past API's I've dealt with have been JSON/RESTful so I feel out of my element trying to debug PHP errors.

Edit

I have slowly deleted parts of my method call and parts of my XML string, trying to trigger a different error or something in order to find what I need to fix. What I have found is that by not passing in my XML string, I get a valid response from the $client->FunctionCall(...). It's an "this isn't right" message but it's a message! In fact, passing that function ANYTHING for the xml parameter causes the 500 http faultcode/faultstring. Does this mean that my XMl is poorly formatted or does it mean that there is an issue on their end handling requests?

Second Edit

If I make my $client decleration as follows, I get the faultstring Could not connect to host

$opts = array(
    'ssl' => array('ciphers'=>'RC4-SHA')
  );
$client = new SoapClient($CREDS['orderingWSDL'], array (
"encoding"=>"ISO-8859-1",
'stream_context' => stream_context_create($opts),
  'exceptions'=>true,
));

I am getting more confused the longer I try to fix this.

Tim Roberts
  • 1,120
  • 2
  • 9
  • 25

1 Answers1

8

Sometimes a 500 status coming from a SOAP service could be a SoapFault exception being thrown. To help your troubleshooting, you'll want to be able to inspect both your request XML, and the response XML.

Put your code in try/catch blocks, and use $client->__getLastRequest() and $client->__getLastResponse() to inspect the actual XML.

Example:

$client = new SoapClient('http//xxx.xxx.xxx?wsdl', array('soap_version'=>SOAP_1_1,'trace' => 1,'exceptions' => true));
try {
  $response = $client->someFunction();
  var_dump($response);
} catch (Exception $e)  {
  var_dump($e->getMessage());
  var_dump($client->__getLastRequest());
  var_dump($client->__getLastResponse());
}
Kris Peeling
  • 1,025
  • 8
  • 18
  • 5
    When PHP error reporting is disabled (likely when the server is used in production, such as with default configuration of CentOS 7), the lines above report almost nothing. To see something meaningful, you need to add ini_set('display_errors','On'); at the beginning of the SOAP service, then the solution described above is very useful. It took me hour to figure out it this ^^ – Pierre Apr 07 '18 at 13:13