How do I get a SOAP message in PHP?

OK n00b here with SOAP,

I would like to clarify how to use SOAP.

Question:

I have a Java JSP that hosts WSDL (looks like XML format) for my PHP script, but how can I get this into a PHP script? The WSDL url will be different every time.

I'm sure this is very simple, but just don't understand how or am I not getting it right?

+2


source to share


3 answers


You can try something like this:

try {                                                                                                                                                                           
  if (! ($ xml = file_get_contents ('php: // input'))) {
    throw new Exception ('Could not read POST data.');
  }
} catch (Exception $ e) {
  print ('Did not successfully process HTTP request:'. $ e-> getMessage ());
  exit;
}


This will read the body of the POST request to the $ xml variable and print an error if any.

+6


source


Do you mean the JSP is sending the WSDL in the POST request to the PHP script? If so, take a look at the $ _POST array. If you point out exactly how the JSP submits, I can probably help you.



Anyway, if you have a WSDL url in a variable in your PHP script, you can have a SoapClient class on it .

0


source


Assuming the best scenario:

$soapClient = new SoapClient($wsdlUrl, $soapOptions);
$soapClient->callYourMethod();

      

But when using SOAP, you are likely to run into a lot of brick walls. Here's the documentation for the SoapClient .

Edit:

So WSDL POST-ed. You can then access it either using $HTTP_RAW_POST_DATA

if the XML string was submitted as an HTTP body, or using $_FILES

superglobal if the XML string was sent as part of a multipart request.

Something like that:

$wsdl = $HTTP_RAW_POST_DATA;
$wsdlUrl = 'data:text/xml;base64,' . base64_encode($wsdl);
$soapClient = new SoapClient($wsdlUrl);

      

Anyway, $HTTP_RAW_POST_DATA

only available if php.ini is enabled always_populate_raw_post_data

. Also, if the request was multiple, this parameter is ignored, $HTTP_RAW_POST_DATA

not populated, but you can access the hosted parts with $_FILES

. And you can use php://input

instead $HTTP_RAW_POST_DATA

.

Also, the data URI can only be used when allow_url_fopen

enabled in php.ini.

0


source







All Articles