Choose among multiple services, multiple ports

Thursday, June 19, 2008

If your wsdl has multiple services and multiple ports, You can tell your PHP client to use a preferred service and port by setting "serviceName" and "portName" option in the WSClient.

For an example if you take wsdl1.1 with multiple services and ports like this,

<wsdl:service name=\"Adder1\">
<wsdl:port name=\"SOAP11port_http\" binding=\"ns0:AdderSOAP11Binding\">

<soap:address location=\"http://localhost:8080/axis2/services/Adder1\"/>
<wsdl:port name=\"SOAP12port_http\" binding=\"ns0:AdderSOAP12Binding\">

<soap12:address location=\"http://localhost:8080/axis2/services/Adder1\"/>
<wsdl:service name=\"Adder2\">

<wsdl:port name=\"SOAP11port_http\" binding=\"ns0:AdderSOAP11Binding\">
<soap:address location=\"http://localhost:8080/axis2/services/Adder2\"/>

<wsdl:port name=\"SOAP12port_http\" binding=\"ns0:AdderSOAP12Binding\">
<soap12:address location=\"http://localhost:8080/axis2/services/Adder2\"/>


You can select the Adder2 service with SOAP12port_http with the following optional arguments to the getProxy method.

$client = new WSClient(array(\"wsdl\" => \"your_wsdl\"));

$proxy =
$client->getProxy(\"Adder2\", \"SOAP12Port_http\");

This can be represented in wsdl2 as following,

<service name=\"Adder1\" interface=\"ns0:AdderPortType\">
<endpoint name=\"SOAP11port_http\" binding=\"ns0:SOAP11Binding\" address=\"http://localhost:8080/axis2/services/Adder1\"/>

<endpoint name=\"SOAP12port_http\" binding=\"ns0:AdderSOAP12Binding\" address=\"http://localhost:8080/axis2/services/Adder1\"/>

<service name=\"Adder2\" interface=\"ns0:AdderPortType\">
<endpoint name=\"SOAP11port_http\" binding=\"ns0:SOAP11Binding\" address=\"http://localhost:8080/axis2/services/Adder2\"/>

<endpoint name=\"SOAP12port_http\" binding=\"ns0:AdderSOAP12Binding\" address=\"http://localhost:8080/axis2/services/Adder2\"/>

Note that here portName you provided is considered as the endpoint name under the selected service.

When you don't provide either serviceName and the portName, wsf/php will pick the first serviceName and portName listed in the wsdl.

Although multiple services in the same wsdl is very rare, multiple ports /endpoints in the same service is very common. Specially when you support multiple versions of SOAP, addressing, or even completely different policies for the interface you will surely be having multiple ports.


blog-man said...

I am connecting to a WCF (Windows .NET) web service and the wsdl has multiple services with multiple ports... unfortunately for me, the options you mentioned here are not working in the 2.0 release, so I have to manually specify the endpoint and the soap version (1.1).
I just looked through the client logs and it keeps wanting to connect with soap version 2, so the action is not present according to the soap fault.
I wonder if this is related to having a PEM certificate in the picture?

Dimuthu said...

I think You should try,
$proxy = $client->getProxy($service_name, $port_name);

I corrected it in the post.Please check.

blog-man said...

Thanks for your prompt reply. I tried your new suggestion, but something is still wrong...
I opened a post @ WSO so we can keep track, you can see the wsdl portion and hopefully help others who will run into this when connecting to Windows WCF web services..