views:

260

answers:

2

Hello,

I am trying to find some kind of php class generator for Web Services (WCF service if that matters) without any luck so far. Any ideas?

thanks

A: 

I'd say there's a dubious benefit from static generation of the classes wrapping a SOAP service in a dynamic language like PHP. What I usually do is just hand-crafting the SOAP HTTP request and then feeding the results to SimpleXMLElement, like:

$Response = new SimpleXMLElement($soap_response_xml);
echo strval($Response->ElementA->ElementB['AttributeC']);

Which corresponds to SOAP response XML:

<Response>
    <ElementA>
        <ElementB AttributeC="foo"/>
    </ElementA>
</Response>

and outputs "foo".

This way has no WSDL parsing overhead. But if you do want to deal with WSDL, and avoid hand-crafting the HTTP request, check this out.

In either way, it's better to "generate the classes" at runtime, because your language allows that.

Ivan Krechetov
Sample of hand-made SOAP request$full_response = @http_post_data( 'http://example.com/ws.asmx', $REQUEST_BODY, array( 'headers' => array( 'Content-Type' => 'text/xml; charset=UTF-8', 'SOAPAction' => 'HotelAvail', ), 'timeout' => 60, ), $request_info);$response_xml = new SimpleXMLElement(strstr($full_response, '<?xml'));
Ivan Krechetov
I'm wondering how well this method will scale (in terms of programming effort) with non-trivial SOAP objects. I'm writing a SOAP client in PHP right now, for example, for a service that has 12 classes with several layers of nesting and multiple inter-class relationships. Does any of that complexity matter for this approach?
Ben Dunlap
We work with even more complex XML of dozens of MB in size. It doesn't matter. You'd call those attributes by name against static classes anyway. AND you save _a lot_ by ignoring WSDL.
Ivan Krechetov
+1  A: 

According to this Question & Answer, you can use the generateProxyCode() method of the PEAR SOAP_WSDL class.

Henrik Opel