Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Trouble Passing Objects using SOAP::Lite

by fogues (Initiate)
on May 27, 2004 at 20:50 UTC ( [id://357050]=perlquestion: print w/replies, xml ) Need Help??

fogues has asked for the wisdom of the Perl Monks concerning the following question:

Dear Monks:
I have a client that passes an ArrayOfEventModel object to a web service. Please refer to the following:

my $data; #...... accumilate information in $data ...... my $events = ArrayOfEventModel->new($data); my $soap; my $som; eval { $soap = SOAP::Lite -> uri(WS_URI()) -> proxy(WS_PROXY()) -> on_action( sub { sprintf '""', @_ } ) -> on_debug( sub { print @_ } ) -> on_fault( sub { } ) ; $som = $soap->processEvent(SOAP::Data->name('arrayOfEventModel +_1')->type(ArrayOfEventModel=>$events)); }; # examines fault and dies if it finds one get_error( $som, $@ );

that throws the following error:

(faultcode) env:Client: (faultdetail) JAXRPC.TIE.01: caught exception while handling request: +deserialization error: unexpected XML reader state. expected: END but + found: START: boroughID

So, $events is an array of EventModel objects, which (like most objects in perl) are hashes. When my request object is created (viewed by printing the debug information):

.............. <arrayOfEventModel_1 xsi:type="SOAP-ENC:ArrayOfEventModel" + SOAP-ENC:arrayType="namesp1:EventModel[1]"> <item xsi:type="namesp1:EventModel"> <name xsi:type="xsd:string">Name</name> <boroughID xsi:type="xsd:int">3</boroughID> <agencyDept xsi:type="xsd:string">Department* </ag +encyDept> <status xsi:type="xsd:string">p</status> <eventImage xsi:type="xsd:string">http://image</ev +entImage> .............

the attributes do not appear in the same order as they are in my WSDL:

....................... <complexType name="ArrayOfEventModel"> <complexContent> <restriction base="soap11-enc:Array"> <attribute ref="soap11-enc:arrayType" wsdl:arrayType="tns: +EventModel[]"/></restriction></complexContent></complexType> <complexType name="EventModel"> <sequence> <element name="ID" type="string"/> <element name="address1" type="string"/> <element name="address2" type="string"/> <element name="address3" type="string"/> <element name="agencyAcronym" type="string"/> <element name="agencyDept" type="string"/> <element name="boroughID" type="int"/> .............................

Is this the reason the error is being thrown?
If so, how do I force a certain order of xml tags in my request?
If not, what else could be causing the problem?

Any thoughts would be appreciated.

Thanks,
Rob

Replies are listed 'Best First'.
Re: Trouble Passing Objects using SOAP::Lite
by rjray (Chaplain) on May 27, 2004 at 23:32 UTC

    This is a shortcoming in the (current) implementation of SOAP::Lite. The problem is that the object, implemented as a hash reference, is just serialized as a hash reference. Thus, there is no concern for the order of the keys. But element-order is significant in XML (unless otherwise stated) when using XML Schema, which most web-services (especially Java- and .NET-based ones) use in their WSDL definitions.

    At the present time, there is no quick, simple solution to this. You have to write your own serializer, and you have to plug it into SOAP::Lite. I wrote an article for O'Reilly that touches on this in the context of talking to .NET services, but it would apply here, as well. The article is Five Tips for .NET Programming in Perl.

    --rjray

      Hi Randy and Monks:

      Thanks for the helpful info! I have got the order sorted out but am having trouble with the namespaces. I reread your article a few times but I must be missing something.

      My old requests had:

      ...<arrayOfEventModel_1 xsi:type="SOAP-ENC:ArrayOfEventModel" SOAP-ENC:arrayType="namesp1:EventModel[1]"> <item xsi:type="namesp1:EventModel">...

      and this was OK. But, the new requests have:

      ...<arrayOfEventModel_1 xsi:type="SOAP-ENC:ArrayOfEventModel" SOAP-ENC:arrayType="xsd:ur-type[1]"> <item>...

      I have noted that $attr (as received by serialize_complex_type) is a zero length string. I assume this impairs the intended namespace handling.

      My plan after this was to review the SOAP::Serialzer package AUTOLOAD sub (assuming it handles the as_whatever__class calls) and reuse some of this code in the serialize_complex_type sub in attempts to preserve the way this part of the serialization is handled. But there is no AUTOLOAD!

      Please let me know how I can locate this code, or if there's another angle to try.

      Thanks in advance,
      Rob

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://357050]
Approved by jfroebe
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others imbibing at the Monastery: (5)
As of 2024-04-19 03:40 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found