3 Replies Latest reply on Sep 26, 2006 9:15 AM by ntsiii

    How do I send XML to a web service?

    ThorLoki
      I am brand new to Flex. I am trying to write a program that uses web services to send and receive data. I have gotten it so that it can receive XML from the web service. However, I also need to send it, and I am stuck.

      I have tried the following code:

      <mx:WebService id="MyService"
      wsdl=" http://localhost/FlexTest/service1.asmx?WSDL"
      useProxy="false"
      result="resultHandler(event)">

      <!-- Input: XML Document...Output: String -->
      <mx:operation name="HelloPersonAcceptsXmlDocumentReturnsString">
      <mx:request>
      <personXmlDoc>xmlPerson</personXmlDoc>
      </mx:request>
      </mx:operation>

      <!-- Input: XML Node...Output: String -->
      <mx:operation name="HelloPersonAcceptsXmlNodeReturnsString">
      <mx:request>
      <personXmlNode>
      xmlPerson.Person
      </personXmlNode>
      </mx:request>
      </mx:operation>

      <!-- Input: String (XML Format)...Output: String -->
      <mx:operation name="HelloPersonAcceptsXmlStringReturnsString">
      <mx:request format="xml">
      <personXmlString><p1:Person xmlns:p1=" http://impact-tech.com/schemas/FlexTest"><p1:ID>f1bd45fc-544b-489d-83cf-349d1f9740ec</p1:I D><p1:FirstName>Joe</p1:FirstName><p1:MiddleName>C.</p1:MiddleName><p1:LastName>Blow</p1:L astName><p1:BirthDate>2006-09-11T14:03:04.4755443-04:00</p1:BirthDate><p1:IsMarried>false< /p1:IsMarried><p1:NumChildren>0</p1:NumChildren><p1:NetWorth>100000</p1:NetWorth></p1:Pers on></personXmlString>
      <!--<personXmlString>{xmlPerson.toXmlString()}</personXmlString>-->
      <!--<personXmlString>{txInput.text}</personXmlString>-->
      </mx:request>
      </mx:operation>

      </mx:WebService>

      In the first operation, "HelloPersonAcceptsXmlDocumentReturnsString", I try to send an XML object. In the second operation, "HelloPersonAcceptsXmlNodeReturnsString", I try to send the root node, xmlPerson.Person. In both cases, what actually gets sent is literally the text that I put in the <request>node, not the object that text is referencing. So for the first, "xmlPerson" gets sent to the target, not the XML doc that it refers to.

      In the third operation, I tried three different things, and two are commented out. I tried to reference the XML object using the toXmlString() method, but again, it literally sent the text "xmlPerson.toXmlString()". I tried the curly-brace binding, but then nothing gets sent to the web service. I also tried building the actual XML document node by node, with values, but I get an error from the web service saying it can't be parsed because there is an illegal character at Line 1, Position1. The only thing which has worked has been to add an Input Text box, copy-and-paste the exact same XML structure as I tried to manually build, and then use binding to the text property of the InputText control. Then it works fine. But I can't actually do that, it's just for testing.

      So my question is how to make a <request> node that is part of the web service operation that references an object and sends the value of that object to the web service, not literally whatever text is typed in that node. I looked at the Web Services and Data Binding sections of the help, and didn't see any examples covering this. Everything was far more simplistic with binding to controls. Can anyone help a newbie, please?