Loading ...
Sorry, an error occurred while loading the content.
 

How to serialize an object?

Expand Messages
  • yf72
    Hi, there I am using SOAP::Lite in perl to communicate a SOAP server (Apache.axis). There is an operation (addMember) needs a class Member as parameter (the
    Message 1 of 4 , Mar 23 10:55 AM
      Hi, there

      I am using SOAP::Lite in perl to communicate a SOAP server
      (Apache.axis). There is an operation (addMember) needs a class
      Member as parameter (the xml message of (request) should look like
      as follows). How can I serialize the member object with SOAP::Lite
      in perl? The Member class is defined in some java bean, which I
      don't have access; and I am using perl not java.

      Any suggestion will be highly appreciated.

      --PerlDev


      <?xml version="1.0" encoding="UTF-8"?>
      <soapenv:Envelope
      xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
      xmlns:xsd="http://www.w3.org/2001/XMLSchema"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
      <soapenv:Body>
      <ns1:addMember
      soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
      xmlns:ns1="http://service.api.application.company.com">
      <member href="#id0"/>
      </ns1:addMember>
      <multiRef id="id0" soapenc:root="0"
      soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
      xsi:type="ns2:Member"
      xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"
      xmlns:ns2="http://bean.api.application.company.com">
      <aliases xsi:type="soapenc:Array"
      soapenc:arrayType="ns2:MemberAlias[2]">
      <item href="#id1"/>
      <item href="#id2"/>
      </aliases>
      <attributeValues xsi:type="soapenc:Array"
      soapenc:arrayType="ns2:AttributeValue[4]">
      <item href="#id3"/>
      <item href="#id4"/>
      <item href="#id5"/>
      <item href="#id6"/>
      </attributeValues>
      <lists xsi:type="soapenc:Array" soapenc:arrayType="ns2:MemberList
      [2]">
      <item href="#id7"/>
      <item href="#id8"/>
      </lists>
      <memberId xsi:type="xsd:string">1</memberId>
      <partitionId xsi:type="xsd:int">1</partitionId>
      </multiRef>
      <multiRef id="id5" soapenc:root="0"
      soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
      xsi:type="ns3:AttributeValue"
      xmlns:ns3="http://bean.api.application.company.com"
      xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/">
      <attributeId xsi:type="xsd:int">5</attributeId>
      <partitionId xsi:type="xsd:int">1</partitionId>
      <value xsi:type="xsd:string">first</value>
      </multiRef>
      <multiRef id="id4" soapenc:root="0"
      soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
      xsi:type="ns4:AttributeValue"
      xmlns:ns4="http://bean.api.application.company.com"
      xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/">
      <attributeId xsi:type="xsd:int">3</attributeId>
      <partitionId xsi:type="xsd:int">1</partitionId>
      <value xsi:type="xsd:string">10/25/2005</value>
      </multiRef>
      <multiRef id="id8" soapenc:root="0"
      soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
      xsi:type="ns5:MemberList"
      xmlns:ns5="http://bean.api.application.company.com"
      xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/">
      <isConfirmed xsi:type="xsd:boolean">false</isConfirmed>
      <isDigest xsi:type="xsd:boolean">false</isDigest>
      <joinApproved xsi:type="xsd:boolean">false</joinApproved>
      <joinStatus xsi:type="xsd:int">0</joinStatus>
      <listId xsi:type="xsd:int">2</listId>
      <memberAliasId xsi:type="xsd:int">12</memberAliasId>
      <needsConfirmation
      xsi:type="xsd:boolean">false</needsConfirmation>
      <needsJoinApproval
      xsi:type="xsd:boolean">false</needsJoinApproval>
      </multiRef>
      <multiRef id="id2" soapenc:root="0"
      soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
      xsi:type="ns6:MemberAlias"
      xmlns:ns6="http://bean.api.application.company.com"
      xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/">
      <emailAddress xsi:type="xsd:string">11@11.11</emailAddress>
      <hardBounceCount xsi:type="xsd:int">2</hardBounceCount>
      <htmlSensing xsi:type="xsd:boolean">false</htmlSensing>
      <lastSendDate xsi:type="xsd:dateTime">2006-03-
      23T06:36:41.951Z</lastSendDate>
      <memberAliasId xsi:type="xsd:int">11</memberAliasId>
      <softBounceCount xsi:type="xsd:int">2</softBounceCount>
      <valid xsi:type="xsd:boolean">true</valid>
      </multiRef>
      <multiRef id="id6" soapenc:root="0"
      soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
      xsi:type="ns7:AttributeValue"
      xmlns:ns7="http://bean.api.application.company.com"
      xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/">
      <attributeId xsi:type="xsd:int">6</attributeId>
      <partitionId xsi:type="xsd:int">1</partitionId>
      <value xsi:type="xsd:string">last</value>
      </multiRef>
      <multiRef id="id1" soapenc:root="0"
      soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
      xsi:type="ns8:MemberAlias"
      xmlns:ns8="http://bean.api.application.company.com"
      xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/">
      <emailAddress xsi:type="xsd:string">12@12.12</emailAddress>
      <hardBounceCount xsi:type="xsd:int">1</hardBounceCount>
      <htmlSensing xsi:type="xsd:boolean">true</htmlSensing>
      <lastSendDate xsi:type="xsd:dateTime">2006-03-
      23T06:36:41.951Z</lastSendDate>
      <memberAliasId xsi:type="xsd:int">12</memberAliasId>
      <softBounceCount xsi:type="xsd:int">1</softBounceCount>
      <valid xsi:type="xsd:boolean">true</valid>
      </multiRef>
      <multiRef id="id7" soapenc:root="0"
      soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
      xsi:type="ns9:MemberList"
      xmlns:ns9="http://bean.api.application.company.com"
      xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/">
      <isConfirmed xsi:type="xsd:boolean">true</isConfirmed>
      <isDigest xsi:type="xsd:boolean">true</isDigest>
      <joinApproved xsi:type="xsd:boolean">true</joinApproved>
      <joinStatus xsi:type="xsd:int">1</joinStatus>
      <listId xsi:type="xsd:int">1</listId>
      <memberAliasId xsi:type="xsd:int">11</memberAliasId>
      <needsConfirmation xsi:type="xsd:boolean">true</needsConfirmation>
      <needsJoinApproval xsi:type="xsd:boolean">true</needsJoinApproval>
      </multiRef>
      <multiRef id="id3" soapenc:root="0"
      soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
      xsi:type="ns10:AttributeValue"
      xmlns:ns10="http://bean.api.application.company.com"
      xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/">
      <attributeId xsi:type="xsd:int">2</attributeId>
      <partitionId xsi:type="xsd:int">1</partitionId>
      <value xsi:type="xsd:string">first@...</value>
      </multiRef>
      </soapenv:Body>
      </soapenv:Envelope>
    • Eric Bridger
      See this about how to use the SOAP::Data object. http://www.majordojo.com/archives/2003_04.html#000008 SOAP::Data objects can be pushed into arrays and point
      Message 2 of 4 , Mar 24 6:58 AM
        See this about how to use the SOAP::Data object.

        http://www.majordojo.com/archives/2003_04.html#000008

        SOAP::Data objects can be pushed into arrays and point to arrays and
        SOAP::Lite should take care of the array typing for you.

        On Thu, 2006-03-23 at 13:55, yf72 wrote:
        > Hi, there
        >
        > I am using SOAP::Lite in perl to communicate a SOAP server
        > (Apache.axis). There is an operation (addMember) needs a class
        > Member as parameter (the xml message of (request) should look like
        > as follows). How can I serialize the member object with SOAP::Lite
        > in perl? The Member class is defined in some java bean, which I
        > don't have access; and I am using perl not java.
        >
        > Any suggestion will be highly appreciated.
        >
        > --PerlDev
        >
        >
        > <?xml version="1.0" encoding="UTF-8"?>
        > <soapenv:Envelope
        > xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
        > xmlns:xsd="http://www.w3.org/2001/XMLSchema"
        > xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
        > <soapenv:Body>
        > <ns1:addMember
        > soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
        > xmlns:ns1="http://service.api.application.company.com">
        > <member href="#id0"/>
        > </ns1:addMember>
        > <multiRef id="id0" soapenc:root="0"
        > soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
        > xsi:type="ns2:Member"
        > xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"
        > xmlns:ns2="http://bean.api.application.company.com">
        > <aliases xsi:type="soapenc:Array"
        > soapenc:arrayType="ns2:MemberAlias[2]">
        > <item href="#id1"/>
        > <item href="#id2"/>
        > </aliases>
        > <attributeValues xsi:type="soapenc:Array"
        > soapenc:arrayType="ns2:AttributeValue[4]">
        > <item href="#id3"/>
        > <item href="#id4"/>
        > <item href="#id5"/>
        > <item href="#id6"/>
        > </attributeValues>
        > <lists xsi:type="soapenc:Array" soapenc:arrayType="ns2:MemberList
        > [2]">
        > <item href="#id7"/>
        > <item href="#id8"/>
        > </lists>
        > <memberId xsi:type="xsd:string">1</memberId>
        > <partitionId xsi:type="xsd:int">1</partitionId>
        > </multiRef>
        > <multiRef id="id5" soapenc:root="0"
        > soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
        > xsi:type="ns3:AttributeValue"
        > xmlns:ns3="http://bean.api.application.company.com"
        > xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/">
        > <attributeId xsi:type="xsd:int">5</attributeId>
        > <partitionId xsi:type="xsd:int">1</partitionId>
        > <value xsi:type="xsd:string">first</value>
        > </multiRef>
        > <multiRef id="id4" soapenc:root="0"
        > soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
        > xsi:type="ns4:AttributeValue"
        > xmlns:ns4="http://bean.api.application.company.com"
        > xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/">
        > <attributeId xsi:type="xsd:int">3</attributeId>
        > <partitionId xsi:type="xsd:int">1</partitionId>
        > <value xsi:type="xsd:string">10/25/2005</value>
        > </multiRef>
        > <multiRef id="id8" soapenc:root="0"
        > soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
        > xsi:type="ns5:MemberList"
        > xmlns:ns5="http://bean.api.application.company.com"
        > xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/">
        > <isConfirmed xsi:type="xsd:boolean">false</isConfirmed>
        > <isDigest xsi:type="xsd:boolean">false</isDigest>
        > <joinApproved xsi:type="xsd:boolean">false</joinApproved>
        > <joinStatus xsi:type="xsd:int">0</joinStatus>
        > <listId xsi:type="xsd:int">2</listId>
        > <memberAliasId xsi:type="xsd:int">12</memberAliasId>
        > <needsConfirmation
        > xsi:type="xsd:boolean">false</needsConfirmation>
        > <needsJoinApproval
        > xsi:type="xsd:boolean">false</needsJoinApproval>
        > </multiRef>
        > <multiRef id="id2" soapenc:root="0"
        > soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
        > xsi:type="ns6:MemberAlias"
        > xmlns:ns6="http://bean.api.application.company.com"
        > xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/">
        > <emailAddress xsi:type="xsd:string">11@11.11</emailAddress>
        > <hardBounceCount xsi:type="xsd:int">2</hardBounceCount>
        > <htmlSensing xsi:type="xsd:boolean">false</htmlSensing>
        > <lastSendDate xsi:type="xsd:dateTime">2006-03-
        > 23T06:36:41.951Z</lastSendDate>
        > <memberAliasId xsi:type="xsd:int">11</memberAliasId>
        > <softBounceCount xsi:type="xsd:int">2</softBounceCount>
        > <valid xsi:type="xsd:boolean">true</valid>
        > </multiRef>
        > <multiRef id="id6" soapenc:root="0"
        > soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
        > xsi:type="ns7:AttributeValue"
        > xmlns:ns7="http://bean.api.application.company.com"
        > xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/">
        > <attributeId xsi:type="xsd:int">6</attributeId>
        > <partitionId xsi:type="xsd:int">1</partitionId>
        > <value xsi:type="xsd:string">last</value>
        > </multiRef>
        > <multiRef id="id1" soapenc:root="0"
        > soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
        > xsi:type="ns8:MemberAlias"
        > xmlns:ns8="http://bean.api.application.company.com"
        > xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/">
        > <emailAddress xsi:type="xsd:string">12@12.12</emailAddress>
        > <hardBounceCount xsi:type="xsd:int">1</hardBounceCount>
        > <htmlSensing xsi:type="xsd:boolean">true</htmlSensing>
        > <lastSendDate xsi:type="xsd:dateTime">2006-03-
        > 23T06:36:41.951Z</lastSendDate>
        > <memberAliasId xsi:type="xsd:int">12</memberAliasId>
        > <softBounceCount xsi:type="xsd:int">1</softBounceCount>
        > <valid xsi:type="xsd:boolean">true</valid>
        > </multiRef>
        > <multiRef id="id7" soapenc:root="0"
        > soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
        > xsi:type="ns9:MemberList"
        > xmlns:ns9="http://bean.api.application.company.com"
        > xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/">
        > <isConfirmed xsi:type="xsd:boolean">true</isConfirmed>
        > <isDigest xsi:type="xsd:boolean">true</isDigest>
        > <joinApproved xsi:type="xsd:boolean">true</joinApproved>
        > <joinStatus xsi:type="xsd:int">1</joinStatus>
        > <listId xsi:type="xsd:int">1</listId>
        > <memberAliasId xsi:type="xsd:int">11</memberAliasId>
        > <needsConfirmation xsi:type="xsd:boolean">true</needsConfirmation>
        > <needsJoinApproval xsi:type="xsd:boolean">true</needsJoinApproval>
        > </multiRef>
        > <multiRef id="id3" soapenc:root="0"
        > soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
        > xsi:type="ns10:AttributeValue"
        > xmlns:ns10="http://bean.api.application.company.com"
        > xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/">
        > <attributeId xsi:type="xsd:int">2</attributeId>
        > <partitionId xsi:type="xsd:int">1</partitionId>
        > <value xsi:type="xsd:string">first@...</value>
        > </multiRef>
        > </soapenv:Body>
        > </soapenv:Envelope>
        >
        >
        >
        >
        >
        >
        >
        > Yahoo! Groups Links
        >
        >
        >
        >
        >
      • Eric Bridger
        ... But you can use the SOAP::Data object to build the paramters you are sending to the axis server. See this post about the $service- call() method which
        Message 3 of 4 , Mar 24 1:30 PM
          On Fri, 2006-03-24 at 16:04, yf72 wrote:
          > It's apache.axis doesn't recognize the serailized Member object by
          > SOAP::Lite... Not SOAP::Lite deserialize.
          >

          But you can use the SOAP::Data object to build the paramters you are
          sending to the axis server. See this post about the $service->call()
          method which allows you to fully customize your request.

          http://www.majordojo.com/archives/000009.php

          See also the call method documentation at:
          http://www.majordojo.com/soaplite/docs/SOAP/Lite.html#METHODS

          Here's some code:
          ========================

          # Connect to the service
          my $service = SOAP::Lite
          ->proxy('http://some/url/')
          ;

          my $site_no = '';
          $site_no = shift or $site_no = '06307616';

          my $method_name = 'getInfoBySiteNo';

          my $method = SOAP::Data
          ->name($method_name)
          ->prefix('tns')
          ->uri('http://systinet.com/wsdl/gov/nwis/api/');

          my $site_params =
          SOAP::Data
          ->attr({'xmlns:ns1' =>
          'http://systinet.com/wsdl/gov/nwis/model/'})
          ->name(
          'tns:siteNo' => \SOAP::Data->value(
          SOAP::Data->name( 'ns1:siteNo' =>
          $site_no)->type('string')),
          );

          # Pass the both method and params to the service.
          my $site_response = $service->call($method
          => $site_params
          );

          Eric
        • yf72
          either $client- call($method = @params) or $client- method(@params) will produce NESTED xml like: ..
          Message 4 of 4 , Mar 31 10:20 AM
            either $client->call($method => @params) or
            $client->method(@params) will produce NESTED xml like:

            <method customizedAttrs>
            <multiRef>..</muliRef>
            </method>

            Is it possible to use multirefinplace(1)? I couldn't find any sample
            code of how to use multirefinplace.

            The similar issue of multiref was aslo reported at:
            http://groups.google.com/group/comp.lang.perl.modules/browse_frm/thread/360922bcc7c676f9/b34610556100e55e?q=SOAP+multiref&rnum=1#b34610556100e55e

            --- In soaplite@yahoogroups.com, Eric Bridger <eric@...> wrote:
            >
            > On Fri, 2006-03-24 at 16:04, yf72 wrote:
            > > It's apache.axis doesn't recognize the serailized Member object by
            > > SOAP::Lite... Not SOAP::Lite deserialize.
            > >
            >
            > But you can use the SOAP::Data object to build the paramters you are
            > sending to the axis server. See this post about the $service->call()
            > method which allows you to fully customize your request.
            >
            > http://www.majordojo.com/archives/000009.php
            >
            > See also the call method documentation at:
            > http://www.majordojo.com/soaplite/docs/SOAP/Lite.html#METHODS
            >
            > Here's some code:
            > ========================
            >
            > # Connect to the service
            > my $service = SOAP::Lite
            > ->proxy('http://some/url/')
            > ;
            >
            > my $site_no = '';
            > $site_no = shift or $site_no = '06307616';
            >
            > my $method_name = 'getInfoBySiteNo';
            >
            > my $method = SOAP::Data
            > ->name($method_name)
            > ->prefix('tns')
            > ->uri('http://systinet.com/wsdl/gov/nwis/api/');
            >
            > my $site_params =
            > SOAP::Data
            > ->attr({'xmlns:ns1' =>
            > 'http://systinet.com/wsdl/gov/nwis/model/'})
            > ->name(
            > 'tns:siteNo' => \SOAP::Data->value(
            > SOAP::Data->name( 'ns1:siteNo' =>
            > $site_no)->type('string')),
            > );
            >
            > # Pass the both method and params to the service.
            > my $site_response = $service->call($method
            > => $site_params
            > );
            >
            > Eric
            >
          Your message has been successfully submitted and would be delivered to recipients shortly.