Using the 'classmap' with SOAP in PHP

I’ve recently done a little bit of SOAP work whilst spec’ing out a project for work – and I noticed that the PHP manual page for SOAP a mention of the ‘classmap’, which isn’t documented so well. I thought I’d put an example here to show it’s usage.

Whilst you don’t really need to understand specifically what the code below is doing, I shall explain anyway. The code is for locating a service end point for a Postini managed email address. The reason they have a service locator like this is that Postini have many clusters of servers, where each cluster is physically separate from each other – so to manage an account you need to find out where it is first.

Looking at the WSDL XML, we can see how the types are defined:

We can also see the operation we are interested in:

The code below shows me creating the classes we need to support the above. We could improve this by altering the ‘setService’ method of the GetServiceEndpoint class to ensure the parameter refers to a valid service, as specified in the enumeration in the WSDL. We should also improve this code by adding error handling, but for the purposes of this blog post it is removed.

As you can see from the output below, the correct object type is returned.

One important point to take note, is that if there was a constructor for GetServiceEndpointResponse – it would NOT be called.

4 thoughts on “Using the 'classmap' with SOAP in PHP”

  1. Great !
    Thanks to your example my call works !
    With this kind of working, parameters of Soap Call function are embedded into the soap function, else, parameters are out of the call …

    Thanks, lots of works avoided !


  2. In my project I am working on I don’t know if classmap can map classes like this:

    ‘classmap’ => array (
    “NameOfSoapObject” => “NameOfPhpObject”

    this two object are the same, but they have difrent names, because very complex reason, which I can’t tell.

    My SOAP request doesn’t work. Maybe because of this?


Leave a Reply

Your email address will not be published. Required fields are marked *