SOAP::Lite's API allows you to call remote Web service operations easily within your code. Simply instantiate an instance of a service, and execute (or call) the remote method directly from your service instance. For example, a call might look like "$soap->myMethod(arguments)." However, while this convention makes for a nice API, by calling the method in this way you give up control over the attributes of the root SOAP Body element. So how do you change the namespace, the prefix, or attributes of the root element?
The secret in changing the root element is to make use of the call subroutine. This allows you to specify a SOAP::Data element (or string) as the method name, and then a set of SOAP::Data elements as parameters. For example:
my $method = SOAP::Data
->name("myMethodName")
->prefix("ns")
->uri("urn:MerchantAccountService")
->type("ns:Merchant");
my $service->call($method => SOAP::Data->name("param" => "value");
Will produce a SOAP Body that looks like this:
<soap:Body>
<ns:myMethodName xmlns:ns="urn:MerchantAccountService" xsi:type="ns:Merchant">
<param>value</param>
</ns:myMethodName>
</soap:Body>
Comments