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

Hi, I need to call a method with 3 parameters. It should be easy , but one of this parameters is a ComplexType defined in a wsdl file like this :
<complexType name="Context"> <sequence> <element name="agent" type="xsd:boolean"/> <element name="deliveryBlockedByApproval" type="xsd:boolean"/> <element name="fiabilisation" type="xsd:boolean"/> <element name="fromDispatch" type="xsd:boolean"/> <element name="fromEmission" type="xsd:boolean"/> <element name="fromSite" type="xsd:boolean"/> <element name="hasComment" nillable="true" type="soapenc:string"/ +> <element name="hasMetaDossier" nillable="true" type="soapenc:stri +ng"/> <element name="market" nillable="true" type="soapenc:string"/> <element name="mdHasConstraints" type="xsd:boolean"/> <element name="user" nillable="true" type="soapenc:string"/> </sequence> </complexType>
I build the Complextype with the SOAP::Data::ComplexType mod and when i call the method i have this error message :
Type 'Context' can't be found in a schema class 'SOAP::Serializer'
FYI the complex type looks like this :
<?xml version="1.0" encoding="UTF-8"?> <SOAP:ENV xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:namesp2="http://namespaces.soaplite.com/perl" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"> <namesp1:Context xmlns:namesp1="http://wsprod.egencia.com/services/D +eliveryWS?wsdl" xsi:type="namesp2"> <agent xsi:type="xsd:int">1</agent> <user xsi:type="xsd:string">jbbec</user> </namesp1:Context> </SOAP:ENV>
the way i build the complex type is :
my $request_obj = ContextType_inner->new({Context=>{ user => 'jbbec', agent => 1 }}); print $request_obj->as_xml_data;# it's printing what is written above
and the mod ContextType_inner.pm is like :
package ContextType; use strict; use warnings; use SOAP::Data::ComplexType; use vars qw(@ISA); @ISA = qw(SOAP::Data::ComplexType); use constant OBJ_URI => 'http://my_serv/services/DeliveryWS?wsdl'; use constant OBJ_TYPE => ''; use constant OBJ_FIELDS => { user => ['string', undef, undef], agent => ['int', undef, undef], }; sub new { my $proto = shift; my $class = ref($proto) || $proto; my $data = shift; my $obj_fields = shift; $obj_fields = defined $obj_fields && ref($obj_fields) eq 'HASH' +? {%{$obj_fields}, %{+OBJ_FIELDS}} : OBJ_FIELDS; my $self = $class->SUPER::new($data, $obj_fields); return bless($self, $class); } package ContextType_inner; use strict; use warnings; use SOAP::Data::ComplexType; use vars qw(@ISA); @ISA = qw(SOAP::Data::ComplexType); use constant OBJ_URI => 'http://my_serv/services/DeliveryWS?wsdl'; use constant OBJ_TYPE => ''; use constant OBJ_FIELDS => { Context => [ [ ContextType::OBJ_TYPE, ContextType::OBJ_FIELDS ], ContextType::OBJ_URI, undef ] }; sub new { my $proto = shift; my $class = ref($proto) || $proto; my $data = shift; my $obj_fields = shift; $obj_fields = defined $obj_fields && ref($obj_fields) eq 'HASH +' ? {%{$obj_fields}, %{+OBJ_FIELDS}} : OBJ_FIELDS; my $self = $class->SUPER::new($data, $obj_fields); return bless($self, $class); }
Could someone help me please ?

Replies are listed 'Best First'.
Re: using a client SOAP with SOAP::Lite with ComplexType
by gellyfish (Monsignor) on May 11, 2006 at 14:49 UTC

    As I asked when you posted this to SOAP-DISCUSS list, it looks like you have somehow managed to get the SOAP envelope to omit the Body part, if you could show us the client code that is causing the error then we probably can help you from there.

    /J\

      ok here is my client code :
      #!/usr/bin/perl use Data::Dumper; use SOAP::Lite; use SOAP::Data::ComplexType; use ContextType; my $soap = new SOAP::Lite uri => 'http://my_serv/services/DeliveryWS?wsdl', proxy => 'http://my_serv/services/DeliveryWS?wsdl' ; my $request_obj = ContextType_inner->new({Context=>{ user => 'jbbec', agent => 1 }}); $soap->soapversion(1.2); print $soap->changeDeliveryState(\SOAP::Data->value($request_obj->as_s +oap_data),526101,2)->faultstring; 1;
      thank you

        When I run your code I get an envelope which looks on balance to okay:

        <?xml version="1.0" encoding="UTF-8"?> <Envelope xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:namesp2="http://namespaces.soaplite.com/perl" soap:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <Body> <changeDeliveryState xmlns="http://my_serv/services/DeliveryWS?wsd +l"> <c-gensym3> <namesp1:Context xmlns:namesp1="http://my_serv/services/Delive +ryWS?wsdl" xsi:type="namesp2"> <agent xsi:type="xsd:int">1</agent> <user xsi:type="xsd:string">jbbec</user> </namesp1:Context> </c-gensym3> <c-gensym8 xsi:type="xsd:int">526101</c-gensym8> <c-gensym10 xsi:type="xsd:int">2</c-gensym10> </changeDeliveryState> </Body> </Envelope>
        Although the extra <c-gensym3 /> element seems to be erroneous and can be removed by changing the \SOAP::Data->value($request_obj->as_soap_data) to simply $request_obj->as_soap_data. The missing namespace prefix on the SOAP envelope would appear to be a bug in SOAP::Lite and can be fixed by omitting the setting of the soapversion().

        However I suspect that your actual error might be coming from elsewhere, could you post the output you get when you use:

        use SOAP::Lite +trace => 'all';
        So we can see what XML is actually being generated and returned.

        /J\