Viewed   610 times

I am unable to convert SOAP response to Array in php.

here is the code

 $response = $client->__doRequest($xmlRequest,$location,$action,1);

here is the SOAP response.

<soap:envelope xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:body>
<searchflightavailability33response xmlns="http://FpwebBox.Fareportal.com/Gateway.asmx">
<searchflightavailability33result>
    &lt;Fareportal&gt;&lt;FpSearch_AirLowFaresRS&gt;&lt;CntKey&gt;1777f5a7-7824-46ce-a0f8-33d5e6e96816&lt;/CntKey&gt;&lt;Currency CurrencyCode="USD"/&gt;&lt;OriginDestinationOptions&gt;&lt;OutBoundOptions&gt;&lt;OutBoundOption segmentid="9W7008V21Feb14"&gt;&lt;FlightSegment etc....
    </searchflightavailability33result>
</searchflightavailability33response>
</soap:body>
</soap:envelope>;

i used the following ways to convert to Array,but i am getting empty output.

1.echo '<pre>';print_r($client__getLastResponse());
2.echo '<pre>';print_r($response->envelope->body->searchflightavailability33response);
3.echo '<pre>';print_r($client->SearchFlightAvailability33($response));
     4.simplexml_load_string($response,NULL,NULL,"http://schemas.xmlsoap.org/soap/envelope/");  

5.echo '<pre>';print_r($client->SearchFlightAvailability33($response));

please advice me.

 Answers

1

finally i found the solution is

we can get body of the response from SOAP the following ways

example1:

$xml = new SimpleXMLElement($soapResponse);
foreach($xml->xpath('//soap:body') as $header) {
    $output = $header->registerXPathNamespace('default', 'http://FpwebBox.Fareportal.com/Gateway.asmx');    
}

example2:

$doc = new DOMDocument('1.0', 'utf-8');
    $doc->loadXML( $soapResponse );
    $XMLresults     = $doc->getElementsByTagName("SearchFlightAvailability33Response");
    $output = $XMLresults->item(0)->nodeValue;
Friday, October 28, 2022
1
$array = explode(' ', $string);
Tuesday, October 4, 2022
5

Here is the solution. :)

<?php
$url    = 'http://example.com/sampleapi/test.asmx?WSDL';
$client = new SoapClient($url, array("soap_version" => SOAP_1_1,"trace" => 1));

$user_param = array (
  'WebProviderLoginId' => "test",
  'WebProviderPassword' => "test",
  'IsAgent' => false
);

$service_param = array (
  'objSecurity' => $user_param,
  "OutPut" => NULL,
  "ErrorMsg" => NULL
);

print_r(
   $client->__soapCall(
       "Login",
       array($service_param)
   )
);

echo $client->__getLastRequest();

?>

& the request was:

<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://tempuri.org/Example/Service1">
<SOAP-ENV:Body>
   <ns1:Login>
       <ns1:objSecurity>
           <ns1:WebProviderLoginId>test</ns1:WebProviderLoginId>
           <ns1:WebProviderPassword>test</ns1:WebProviderPassword>
           <ns1:IsAgent>false</ns1:IsAgent>
       </ns1:objSecurity>
   </ns1:Login>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>

Thanks to this link. PHP SOAP Request not right

Sunday, December 25, 2022
 
3

Upfront remark: In order to use the __getLastRequest() method successfully, you have to set the 'trace' option to true on client construction:

$client = new SoapClient('wsdldoc.asmx?WSDL', array('trace' => TRUE));

This way, your request will still be sent (and therefore still fail), but you can inspect the sent xml afterwards by calling $client->__getLastRequest().


Main answer:

To get access to the generated XML before/without sending the request, you'd need to subclass the SoapClient in order to override the __doRequest() method:

class SoapClientDebug extends SoapClient
{
  public function __doRequest($request, $location, $action, $version, $one_way = 0) {
      // Add code to inspect/dissect/debug/adjust the XML given in $request here

      // Uncomment the following line, if you actually want to do the request
      // return parent::__doRequest($request, $location, $action, $version, $one_way);
  }
}

You'd then use this extended class instead of the original SoapClient while debugging your problem.

Wednesday, August 31, 2022
 
5
<?php
//Note I changed the json a bit to make it parsable

$json = '{ "provider":{ "id":"1982660171", "display_name":"Stephen R Guy, MD", "last_name":"Guy", "first_name":"Stephen", "middle_name":"Russell", "master_name":"Stephen_Guy", "degree_types":"MD", "familiar_name":"Stephen", "years_experience":"27", "birth_year":"1956", "birth_month":"5", "birth_day":"23", "gender":"M", "is_limited":"false", "url_deep":"http:\/\/www.vitals.com\/doctor\/profile\/1982660171\/Stephen_Guy", "url_public":"http:\/\/www.vitals.com\/doctors\/Dr_Stephen_Guy.html", "status_code":"A", "client_ids":"1", "quality_indicator_set":[ { "type":"quality-indicator\/consumer-feedback", "count":"2", "suboverall_set":[ { "name_short":"Promptness", "overall":"3" }, { "name_short":"Courteous Staff", "overall":"4" }, { "name_short":"Bedside Manner", "overall":"4" }, { "name_short":"Spends Time with Me", "overall":"4" }, { "name_short":"Follow Up", "overall":"4" } ], "name":"Consumer Reviews", "overall":"4.0", "measure_set":[ { "feedback_response_id":"1756185", "input_source_ids":"{0}", "date":"1301544000", "value":"4", "scale":{ "best":"1", "worst":"4" }, "review":{ "type":"review\/consumer", "comment":"I will never birth with another dr. Granted that's not saying much as I don't like dr's but I actually find him as valuable as the midwives who I adore. I liked Horlacher but when Kitty left I followed the midwives and then followed again....Dr. Guy is GREAT. I honestly don't know who I'd rather support me at my birth; Margie and Lisa or Dr. Guy. ....I wonder if I can just get all of them.Guy's great. Know what you want. Tell him. Be strong and he'll support you.I give him 10 stars. Oh...my baby's 3 years old now. He's GREAT! ", "date":"1301544000" }, "sub_measure":[ { "name":"Waiting time during a visit", "name_short":"Promptness", "value":"3", "scale":{ "best":"4", "worst":"1" } }, { "name":"Courtesy and professionalism of office staff ", "name_short":"Courteous Staff", "value":"4", "scale":{ "best":"4", "worst":"1" } }, { "name":"Bedside manner (caring)", "name_short":"Bedside Manner", "value":"4", "scale":{ "best":"4", "worst":"1" } }, { "name":"Spending enough time with me", "name_short":"Spends Time with Me", "value":"4", "scale":{ "best":"4", "worst":"1" } }, { "name":"Following up as needed after my visit", "name_short":"Follow Up", "value":"4", "scale":{ "best":"4", "worst":"1" } } ] }, { "feedback_response_id":"420734", "input_source_ids":"{76}", "link":"http:\/\/local.yahoo.com\/info-15826842-guy-stephen-r-md-university-women-s-health-center-dayton", "date":"1142398800", "value":"4", "scale":{ "best":"1", "worst":"4" }, "review":{ "type":"review\/consumer", "comment":"Excellent Doctor: I really like going to this office. They are truely down to earth people and talk my \"non-medical\" language. I have been using thier office since 1997 and they have seen me through 2 premature pregnancies!", "date":"1142398800" } } ], "wait_time":"50" } ] } } ';

$obj = json_decode($json);

//This is how you can retrieve data 
print $obj->{'provider'}->{'id'};
?>
Sunday, October 16, 2022
 
slcott
 
Only authorized users can answer the search term. Please sign in first, or register a free account.
Not the answer you're looking for? Browse other questions tagged :