tags:

views:

517

answers:

3

OK n00b here with SOAP,

Would like some clarification on how to use SOAP.

Question:

I have a Java JSP that posts a WSDL (Looks like XML format) to my PHP script, but how do I get this in the PHP script? The URL for the WSDL will be different every time.

I'm sure it's very simple but just don't see how or am I not understanding this correctly?

+2  A: 

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 there is one.

Lucas Oman
Never seen this "php://input", does this read the RAW post data?
Phill Pafford
Thanks this works great
Phill Pafford
A: 

Do you mean that the JSP sends the WSDL in a POST request to the PHP script? If so, have a look at the $_POST array. If you specify exactly how the JSP sends it, I can probably help you more.

Anyway, once you have the WSDL url in a variable in your PHP script, you can have at it with the SoapClient class.

gnud
Yes this is the route Im talking about, so maybe I could just consume the RAW post and parse it out that way?
Phill Pafford
A: 

Assuming the best scenario:

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

But you're likely to hit a lot of brick walls when using SOAP. Here's the documentation for SoapClient.

Edit:

So, the WSDL is POST-ed. Then, you could access it either by using $HTTP_RAW_POST_DATA if the XML string was sent as the HTTP body, or by using the $_FILES superglobal if the XML string was send as a part of a multipart request.

Something like this:

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

Anyway, $HTTP_RAW_POST_DATA is only available if the php.ini setting always_populate_raw_post_data is turned on. Also, if the request was multipart, this setting is ignored, $HTTP_RAW_POST_DATA is not populated but you get access to the posted parts using $_FILES. And you may, indeed, use php://input instead of $HTTP_RAW_POST_DATA.

Also, data URIs may only be used when allow_url_fopen is turned on in php.ini.

Ionuț G. Stan
but how do I get the $wsdlUrl? this is what changes everytime the I need the PHP script to handle
Phill Pafford
Here the URL contains the data itself: The URL protocol is not http, but data. If the SoapClient class handles this, then that's the best solution.
gnud