0 Replies Latest reply on Jan 3, 2007 7:58 PM by eborsboom

    Passing XML arguments to a web service operation

    eborsboom
      Subject: Passing XML arguments to a web service operation

      I have a web service with an operation that expects its arguments to be a arbitrary XML.
      When I try to pass an XML object using the operation's send() method, the XML is passed to the web
      service as an entity encoded string rather than just XML (e.g. "<foo>bar</foo>" is
      sent instead of "<foo>bar</foo>").


      Here is the code that I use to call the web service:


      Client.current.testService.getAlbums.send(
      <GetAlbumsCriteria>
      <AlbumID>{albumsGrid.value.ID}</AlbumID>
      </GetAlbumsCriteria>,
      <GetAlbumsInclude>
      <Tracks>true</Tracks>
      </GetAlbumsInclude>);




      This is the SOAP request that gets sent:


      <?xml version="1.0" encoding="utf-8"?>
      <SOAP-ENV:Envelope xmlns:xsi=" http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd=" http://www.w3.org/2001/XMLSchema" xmlns:SOAP-ENV=" http://schemas.xmlsoap.org/soap/envelope/"><SOAP-ENV:Header><ns1:Session xmlns:ns1=" http://example.com/WebServices"><ns1:SessionID>2105806011</ns1:SessionID></ns1:Session></S OAP-ENV:Header><SOAP-ENV:Body><getAlbums xmlns=" http://example.com/WebServices/TestService"><ns1:criteria xmlns:ns1=" http://example.com/WebServices/TestService">&lt;GetAlbumsCriteria&gt;
      &lt;AlbumID&gt;
      &lt;ID xmlns:xsd=&quot; http://www.w3.org/2001/XMLSchema&quot; xmlns:soap=&quot; http://schemas.xmlsoap.org/soap/envelope/&quot; xmlns:xsi=&quot; http://www.w3.org/2001/XMLSchema-instance&quot;&gt;3958&lt;/ID&gt;
      &lt;/AlbumID&gt;
      &lt;/GetAlbumsCriteria&gt;</ns1:criteria><ns0:include xmlns:ns0=" http://example.com/WebServices/TestService">&lt;GetAlbumsInclude&gt;
      &lt;Tracks&gt;true&lt;/Tracks&gt;
      &lt;/GetAlbumsInclude&gt;</ns0:include></getAlbums></SOAP-ENV:Body></SOAP-ENV:Envelope>




      Here's the request that SHOULD be sent:


      <?xml version="1.0" encoding="utf-8"?>
      <SOAP-ENV:Envelope xmlns:xsd=" http://www.w3.org/2001/XMLSchema" xmlns:SOAP-ENV=" http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi=" http://www.w3.org/2001/XMLSchema-instance"><SOAP-ENV:Header><ns1:Session xmlns:ns1=" http://example.com/WebServices"><ns1:SessionID>504183852</ns1:SessionID></ns1:Session></SO AP-ENV:Header><SOAP-ENV:Body><getAlbums xmlns=" http://example.com/WebServices/TestService"><ns1:criteria xmlns:ns1=" http://example.com/WebServices/TestService"><GetAlbumsCriteria xmlns=""><AlbumID xmlns="">3958</AlbumID></GetAlbumsCriteria></ns1:criteria><ns0:include xmlns:ns0=" http://example.com/WebServices/TestService"><GetAlbumsInclude xmlns=""><Tracks xmlns="">true</Tracks></GetAlbumsInclude></ns0:include></getAlbums></SOAP-ENV:Body></SOAP -ENV:Envelope>




      I've tried various different ways of passing the parameters to achieve this. For example, passing ActionScript dynamic objects as the arguments actually works, because they are serialized into the right XML format:


      Client.current.testService.getAlbums.send({
      GetAlbumsCriteria: {
      AlbumID: albumsGrid.value.ID}}, {
      GetAlbumsInclude: {
      Tracks: true }});




      However, this workaround doesn't work for me because there are cases where I need to pass more complex XML (with attributes, etc) that the object notation can't do.

      Using the operation.request property instead of passing the arguments to send() doesn't help.

      If I put the XML directly in the <mx:operation> tag in the <mx:WebService> declaration, that does work. But this doesn't help me, because I need to send very different XML each time I call the operation.


      Here's my mx:WebService declaration:


      <mx:WebService id="testService"
      showBusyCursor="true"
      result="testServiceComplete(event)"
      fault="testServiceComplete(event)">

      <mx:operation name="getAlbums"
      result="dashBoardPanel.getAlbumsResult(event)"
      fault="dashBoardPanel.handleGetAlbumsFault(event)"
      resultFormat="e4x">
      </mx:operation>

      </mx:WebService>




      This is the web service operation's method signature on the server (in C#):


      [WebMethod]
      public XmlNode getAlbums(XmlNode criteria, XmlNode include)




      Here's the WSDL (I removed all the operations except getAlbums):


      <?xml version="1.0" encoding="utf-8"?>
      <wsdl:definitions xmlns:soap=" http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tm=" http://microsoft.com/wsdl/mime/textMatching/" xmlns:soapenc=" http://schemas.xmlsoap.org/soap/encoding/" xmlns:mime=" http://schemas.xmlsoap.org/wsdl/mime/" xmlns:tns=" http://example.com/WebServices/TestService" xmlns:s=" http://www.w3.org/2001/XMLSchema" xmlns:soap12=" http://schemas.xmlsoap.org/wsdl/soap12/" xmlns:http=" http://schemas.xmlsoap.org/wsdl/http/" targetNamespace=" http://example.com/WebServices/TestService" xmlns:wsdl=" http://schemas.xmlsoap.org/wsdl/">
      <wsdl:types>
      <s:schema elementFormDefault="qualified" targetNamespace=" http://example.com/WebServices/TestService">
      <s:element name="getAlbums">
      <s:complexType>
      <s:sequence>
      <s:element minOccurs="0" maxOccurs="1" name="criteria">
      <s:complexType mixed="true">
      <s:sequence>
      <s:any />
      </s:sequence>
      </s:complexType>
      </s:element>
      <s:element minOccurs="0" maxOccurs="1" name="include">
      <s:complexType mixed="true">
      <s:sequence>
      <s:any />
      </s:sequence>
      </s:complexType>
      </s:element>
      </s:sequence>
      </s:complexType>
      </s:element>
      <s:element name="getAlbumsResponse">
      <s:complexType>
      <s:sequence>
      <s:element minOccurs="0" maxOccurs="1" name="getAlbumsResult">
      <s:complexType mixed="true">
      <s:sequence>
      <s:any />
      </s:sequence>
      </s:complexType>
      </s:element>
      </s:sequence>
      </s:complexType>
      </s:element>
      </s:schema>
      </wsdl:types>
      <wsdl:message name="getAlbumsSoapIn">
      <wsdl:part name="parameters" element="tns:getAlbums" />
      </wsdl:message>
      <wsdl:message name="getAlbumsSoapOut">
      <wsdl:part name="parameters" element="tns:getAlbumsResponse" />
      </wsdl:message>
      <wsdl:portType name="TestServiceSoap">
      <wsdl:operation name="getAlbums">
      <wsdl:input message="tns:getAlbumsSoapIn" />
      <wsdl:output message="tns:getAlbumsSoapOut" />
      </wsdl:operation>
      </wsdl:portType>
      <wsdl:binding name="TestServiceSoap" type="tns:TestServiceSoap">
      <soap:binding transport=" http://schemas.xmlsoap.org/soap/http" />
      <wsdl:operation name="getAlbums">
      <soap:operation soapAction=" http://example.com/WebServices/TestService/getAlbums" style="document" />
      <wsdl:input>
      <soap:body use="literal" />
      </wsdl:input>
      <wsdl:output>
      <soap:body use="literal" />
      </wsdl:output>
      </wsdl:operation>
      </wsdl:binding>
      <wsdl:service name="TestService">
      <wsdl:port name="TestServiceSoap" binding="tns:TestServiceSoap">
      <soap:address location=" http://example.com/WebServices/TestService.asmx" />
      </wsdl:port>
      </wsdl:service>
      </wsdl:definitions>