0 Replies Latest reply on Sep 14, 2007 8:27 AM by bitwyse

    How to update data from a web service

    bitwyse Level 1
      Hi all,

      I have a webservice that returns some data as e4x type. I pull the data i need and put it into an object. I manipulate that data, then I want to write it back with another webservice. I get serialization errors when I call the update method. I must be doing something wrong here. Can anyone help?

      Webservice Methods:
      <mx:operation name="FetchfrmContact" resultFormat="e4x" result = "fetchfrmContactResultHandler()">
      <mx:request/>
      </mx:operation>
      <mx:operation name="updatefrmContactCampaigns" resultFormat="e4x" result="updatefrmContactCampaignsResultHandler()">
      <mx:request/>
      </mx:operation>


      Below is what .lastResult looks like from the fetch method of the webservice. I update the different campaign fields by adding or removing them in an object called contactData.

      <FetchfrmContactResponse xmlns:xsd=" http://www.w3.org/2001/XMLSchema" xmlns:soapenv=" http://schemas.xmlsoap.org/soap/envelope/" xmlns="urn:DefaultNamespace" xmlns:xsi=" http://www.w3.org/2001/XMLSchema-instance">
      <FetchfrmContactReturn>
      <campaignsOptedOut>
      "BP - 411"
      </campaignsOptedOut>
      <campaignsOptedOut>
      "200700 - Avnet Leads"
      </campaignsOptedOut>
      <campaignsOptedOut>
      "200700 - BP-AdHoc"
      </campaignsOptedOut>
      <campaignsReceived>
      "BP - 411"
      </campaignsReceived>
      <campaignsSubscribed>
      "200700 - Avnet Leads"
      </campaignsSubscribed>
      <campaignsSubscribed>
      "200700 - BP-AdHoc"
      </campaignsSubscribed>
      <campaignsSubscribed>
      "200700 - BP - BCS"
      </campaignsSubscribed>
      <campaignsSubscribed>
      "200700 - BP - Extracomm"
      </campaignsSubscribed>
      <campaignsSubscribed>
      "200700 - BP - IBM"
      </campaignsSubscribed>
      <campaignsSubscribed>
      "BP - 411"
      </campaignsSubscribed>
      <companyDocID>
      "CMDPDN-65HTAK"
      </companyDocID>
      <companyName>
      "Provena Hospitals"
      </companyName>
      <contactDocID>
      "CTGSCG-6AHLWW"
      </contactDocID>
      <contactEmail>
      "srieger@psclistens.com"
      </contactEmail>
      <contactFirst>
      "Steve"
      </contactFirst>
      <contactLast>
      "Rieger"
      </contactLast>
      <docID xsi:nil="true"/>
      <fetchBy>
      "email"
      </fetchBy>
      <form xsi:nil="true"/>
      <locationDocID/>
      </FetchfrmContactReturn>
      </FetchfrmContactResponse>

      The fetch method returns an object of type FrmContactType and the update method takes an object of type FrmContactType as it's parameter

      package com.psc.components
      {
      import mx.collections.ArrayCollection;
      import mx.collections.XMLListCollection;

      [Bindable]
      public class FrmContactType
      {
      // field variables
      public var contactDocID : String;
      public var companyDocID : String;
      public var locationDocID : String;
      public var campaignsOptedOut : XMLListCollection; // SFProfileField_70
      public var campaignsReceived : XMLListCollection; // SFProfileField_68
      public var campaignsSubscribed : XMLListCollection; // SFProfileField_69
      public var contactEmail : String = "";
      public var fetchBy : String;
      public var docID : String;
      public var form : String;
      public var contactFirst : String = "";
      public var contactLast : String = "";
      public var companyName : String = "";

      }
      }

      Here is the result handler of the fetch method
      private function fetchfrmContactResultHandler() : void
      {
      contactData.contactFirst = wsfrmContactLookup.FetchfrmContact.lastResult..contactFirst;
      contactData.contactLast = wsfrmContactLookup.FetchfrmContact.lastResult..contactLast;
      contactData.companyName = wsfrmContactLookup.FetchfrmContact.lastResult..companyName;
      contactData.contactDocID = wsfrmContactLookup.FetchfrmContact.lastResult..contactDocID;

      if( wsfrmContactLookup.FetchfrmContact.lastResult )
      {
      contactData.campaignsReceived = new XMLListCollection( wsfrmContactLookup.FetchfrmContact.lastResult..campaignsReceived );
      contactData.campaignsSubscribed = new XMLListCollection( wsfrmContactLookup.FetchfrmContact.lastResult..campaignsSubscribed );
      contactData.campaignsOptedOut = new XMLListCollection( wsfrmContactLookup.FetchfrmContact.lastResult..campaignsOptedOut );

      if( contactData.campaignsSubscribed.length > 0 )
      {
      for( var index : int = 0; index < checkBoxSubscribed.length; index++ )
      {
      checkBoxSubscribed[index].selected = true;
      }
      }

      if( contactData.campaignsOptedOut.length > 0 )
      {
      for( index = 0; index < checkBoxOptedOut.length; index++ )
      {
      checkBoxOptedOut[index].selected = true;
      }
      }
      }
      }

      In my code I update the contactData object, then call the update method passing contactData as it's parameter and it barks at me. Any ideas why I'd be getting the error message shown below?

      <soapenv:Fault 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">
      <faultcode>
      "soapenv:Server.generalException"
      </faultcode>
      <faultstring>
      "org.xml.sax.SAXException: SimpleDeserializer encountered a child element, which is NOT expected, in something it was trying to deserialize."
      </faultstring>
      <detail/>
      </soapenv:Fault>