Wednesday, October 17, 2018

Calling multiple methods with same name using SoapClient

Leave a Comment

I have a SOAP webservice and in SOAP UI I see that there are methods with the same name. So, for example, there are 2 CreateNewContact methods, one of which takes 3 parameters and the other 4. Below are the stubs generated by SOAP UI

Method 1 Stub:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:rfp="http://test.com/testWebservice/">    <soapenv:Header/>    <soapenv:Body>       <rfp:CreateNewContact_FullName>          <!--Optional:-->          <rfp:fullName>?</rfp:fullName>          <!--Optional:-->          <rfp:email>?</rfp:email>          <!--Optional:-->          <rfp:telNo>?</rfp:telNo>       </rfp:CreateNewContact_FullName>    </soapenv:Body> </soapenv:Envelope> 

Method 2 Stub:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:rfp="http://test.com/testWebservice/">    <soapenv:Header/>    <soapenv:Body>       <rfp:CreateNewContact_FirstLastName>          <!--Optional:-->          <rfp:firstName>?</rfp:firstName>          <!--Optional:-->          <rfp:lastName>?</rfp:lastName>          <!--Optional:-->          <rfp:email>?</rfp:email>          <!--Optional:-->          <rfp:telNo>?</rfp:telNo>       </rfp:CreateNewContact_FirstLastName>    </soapenv:Body> </soapenv:Envelope> 

When I call the CreateNewContact method with 4 parameters using PHP SoapClient, it looks like I'm getting the response from the other method.

How can I specify which method to use using SoapClient?

Thanks,

2 Answers

Answers 1

As you can read here:

If you are using WSDL based SOAP requests and you have more than one operation in your binding (with the same parameters), make sure the style is set to rpc, NOT body! When you specify 'body' here, all that will be transmitted in the request is the parameters for the function call, and SoapServer->handle() will use the first function it finds with the same parameter-makeup to handle the call. The actual method to call will only be included in the request when your type is set to 'rpc', resulting in the expected behavior

Therefore, you should check in your WSDL the operation element, which provides binding information from the abstract operation to the concrete SOAP operation.
For example:

<definitions ....>;     <binding .... >;         <operation .... >;            <soap12:operation soapAction="xs:anyURI" ?                               soapActionRequired="xs:boolean" ?                               style="rpc|document" ?                               wsdl:required="xs:boolean" ? /> ?         </soap12:operation>     </binding>; </definitions> 

The style attribute value, if present, is a string that specifies the style for the operation. The style attribute indicates whether the operation is RPC-oriented (a messages containing parameters and return values) or document-oriented (a message containing documents). If the style attribute is omitted from the soap12:operation element, then the operation inherits the style specified or implied by the soap12:binding element in the containing wsdl:binding element.
So, in short, to solve your problem you should change the operation style from "document" to "rpc" in your WSDL.
As a further reference: https://bugs.php.net/bug.php?id=49169

Answers 2

I have faced the same with travelport universal API, I ended up modifying my local wsdl file to use different name for each method and it worked perfectly.

If You Enjoyed This, Take 5 Seconds To Share It

0 comments:

Post a Comment