2

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

Pico Apico
  • 21
  • 2
  • Is this a SOAP service? (I don't know anything about WCF) – Ben Dunlap Nov 12 '09 at 06:36
  • Yes, it's SOAP but I'm not sure if there is any difference from a simple web service. The WSDL definition seems a bit more complicated in WCF. Using it on the other hand is straight-forward : http://weblogs.asp.net/gunnarpeipman/archive/2007/09/17/using-wcf-services-with-php.aspx – Pico Apico Nov 12 '09 at 06:42
  • 1
    Thanks, I just asked because when I hear "web service" I think of any API that's accessible via HTTP, whether that API uses SOAP, REST, or something else. – Ben Dunlap Nov 12 '09 at 06:49

2 Answers2

1

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

Community
  • 1
  • 1
Henrik Opel
  • 19,341
  • 1
  • 48
  • 64
0

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
  • 18,802
  • 8
  • 49
  • 60
  • 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, ' – Ivan Krechetov Nov 12 '09 at 07:38
  • 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 Nov 12 '09 at 08:32
  • 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 Nov 12 '09 at 08:55