SOAP-WSDL - Is it possible to cast types?

Posted on Wed Jun 25 10:48:14 2008 by rybskej
Is it possible to cast types?
I have a webservice that uses typecasting to determine request processing contexts. For instance, to perform query of Customer on their service, I would need to call the search() method with argument 'searchRecord' cast as a type of CustomerSearchBasic; however, if I wanted to look up employees, I would use the same 'searchRecord' parameter cast as an EmployeeSearchBasic type. Is this possible to do with SOAP::WSDL? I've dug through module documentation and code, and can't see any examples of this being done. The classes that were auto-generated by SOAP::WSDL provided the following:
- element "MyElements::searchRecord" (defines the 'searchRecord' field described earlier)
- base type "MyTypes::SearchRequest" (which contains no fields)
- base type "MyTypes::SearchRecord" (implements the 'searchRecord' field described earlier)
- subclass types "MyTypes::CustomerSearchBasic" and "MyTypes::EmployeeSearchBasic" (each with distinct fields specific to these datatypes)

I was thinking that perhaps I could create an instance of MyTypes::CustomerSearchBasic with no fields, and pass it as an argument like:
my $response = $interface->search( searchPreferences => { #this is a header element; works OK in SOAP::WSDL bodyFieldsOnly => 1, pageSize => 10 }, searchRecord => {} );


But this ends up with an empty body, and doesn't indicate at all how to type-cast searchRecord. I need the searchRecord to be defined with type CustomerSearchBasic. I was thinking that maybe if I could do something like:
MyTypes::CustomerSearchBasic->new(searchRecord => {})


but this doesn't work (complains that field 'searchRecord' doesn't exist in the class). Any ideas on how I can set the searchRecord attribute in the parent class, but pass the type as an instance of MyTypes::CustomerSearchBasic?

As a reference point, the example message below (which works with the target webservice) was successfully hand-generated with SOAP::Lite using SOAP::Data type() and attr() methods.
<?xml version="1.0" encoding="UTF-8"?><soapenv:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema +-instance" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" soapenv:encodingStyle="http:/ +/schemas.xmlsoap.org/soap/encoding/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soapenv="h +ttp://schemas.xmlsoap.org/soap/envelope/"><soapenv:Header><ns1:searchPreferences soap:actor="http: +//schemas.xmlsoap.org/soap/actor/next" xmlns:ns1="urn:messages" soap:mustUnderstand="0"><ns1:bodyF +ieldsOnly>true</ns1:bodyFieldsOnly><ns1:pageSize>10</ns1:pageSize></ns1:searchPreferences></soapen +v:Header><soapenv:Body><search xmlns="urn:messages"><searchRecord xsi:type="ns2:CustomerSearchBasi +c" xmlns:ns2="urn:common"/></search></soapenv:Body></soapenv:Envelope>

Thanks, Eric
Write a response