Michael M.
Michael M.

Reputation: 61

PHP SoapClient returning null when server sends back an error response

I am using PHP SoapClient to send requests to a 3rd party using their WSDL. I have working functionality when I send requests that contain all required data. However, if a required field is missing (or some other minor error) all I'm getting back in my catch is a SoapFault with the message 'Internal Server Error'. Just to make it clear, I have zero control over the server side of the request.

Using SoapUI with the same request I get the following response.

<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
   <s:Body>
      <s:Fault>
         <faultcode>s:Client</faultcode>
         <faultstring xml:lang="en-US">Request validation failed.</faultstring>
         <detail>
            <RequestValidationFault xmlns="http://schemas.datacontract.org/2004/07/OCCM.Phoenix.EWF.Shared.Modules.ERM.Common.BusinessEntities.Exceptions" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
               <Domain>Request validation</Domain>
               <Message>Request validation failed.</Message>
               <ValidationResult xmlns:a="http://schemas.microsoft.com/2003/10/Serialization/Arrays">
                  <a:string>Patient: Last name is required.</a:string>
               </ValidationResult>
            </RequestValidationFault>
         </detail>
      </s:Fault>
   </s:Body>
</s:Envelope>

This is exactly what I need to be able to tell the a user of the system on my end to go in and enter/fix the needed data. In this case the patients last name.

I have exceptions and tracing turned on and when a successful request is made I can use $obj->__getLastResponse() and see the expected data. However when an error comes back the response is '', or 'NULL' if I var_dump() it.

Looking closer in SoapUI I can see that the response has the header:

status HTTP/1.1 500 Internal Server Error

My assumption is that SoapClient is seeing this and just immediately throwing an exception based on the http error. Has anyone had a similar experience with an issue like this? If so, is there a way to tell SoapClient to return the full response?

If that's not possible does anyone know if there is a function I can override to save the raw response text before the exception is thrown? I had an issue earlier where the success XML response was wrapped in meta data. By overriding __doRequest() and manually stripping the meta data I got SoapClient to stop throwing exceptions. This won't work for my current problem as the response is blank there as well.

Upvotes: 4

Views: 820

Answers (1)

Michael M.
Michael M.

Reputation: 61

I was unable to find a solution using SoapClient. I ended up using curl to resend the request when there is an error. Then I manually parsing the actual response.

Upvotes: 2

Related Questions