5 Replies Latest reply on May 9, 2007 11:55 AM by batmitra

    XML-RPC via HTTPService

    TomDavies
      I'm trying to make an XML-RPC call via an HTTPService instance. Is that the best way to do it?

      At present I can generate a request to the correct URL, but the POST seems to be empty. I think that I don't understand what should go in the <mx:request> tag -- I have the literal XML which I want sent:

      <mx:HTTPService
      id="loginRequest"
      url=" http://localhost:8080/rpc/xmlrpc"
      useProxy="false"
      method="POST"
      contentType="application/xml"
      resultFormat="e4x" >
      <mx:request xmlns="" format="xml">
      <methodCall>
      <methodName>confluence1.login</methodName>
      <params>
      <param>
      <value><string>{username.text}</string></value>
      </param>
      <param>
      <value><string>{password.text}</string></value>
      </param>
      </params>
      </methodCall>
      </mx:request>
      </mx:HTTPService>

      Thanks for any advice.

      Tom
        • 1. Re: XML-RPC via HTTPService
          batmitra Level 1
          Hi
          I think you're a bit confused on how to use a HTTPSERVICE

          Weel, the first thing i notice on your code is that you passing on the request an xml well formed format when you should only send the data you want to request, i mean in your case i would strip all of that and leave it like this :

          <mx:request xmlns="" format="xml">

          <methodName>confluence1.login</methodName>
          <value><string>{username.text}</string></value>
          <value><string>{password.text}</string></value>

          </mx:request>

          With this , when you go to your server side language wich i don't know what it is, you must read the stream of http as xml and search for the elements methodname and value , get their data and process it on the server side and then return xml to your flex application.
          You can use POST or GET as your method to make the request, i prefer the GET, the one by default
          • 2. Re: XML-RPC via HTTPService
            TomDavies Level 1
            An XML-RPC request can't use a GET -- the request is in the body, which a GET doesn't have. See http://www.xmlrpc.com/spec if you are interested.

            I'm sure that my server-side XML-RPC library can deal with whitespace in the request.

            But you're correct that I don't understand HTTPService.

            What is the relationship between the contents of the mx:request tag and the resulting HTTP request?

            Thanks,
            Tom
            • 3. Re: XML-RPC via HTTPService
              RIA_Flasher
              I am having a similar problem, when I tried to read the contents of the POST in ASP it is blank.

              i'm sending some xml to asp from flex using the httpservice but when I try to parse the xml using the standard Microsoft.XMLDOM it always fails to parse the xml regardless of what xml I send. This leads me to think that flex is sending the xml incorrectly.

              flex code>

              request = new HTTPService();
              request.url=" http://127.0.0.1/test.asp";
              request.contentType="application/xml"
              request.method="POST"
              request.resultFormat="text"
              request.request = XML(<test>testingxml</test>);
              request.addEventListener(ResultEvent.RESULT, success);
              request.addEventListener(FaultEvent.FAULT, fault);
              request.send();

              private function success(e:mx.rpc.events.ResultEvent):void {
              trace(e.result);
              }

              private function fault(e:mx.rpc.events.FaultEvent):void {
              trace(e.message);
              }

              my ASP code>

              Dim mydoc
              Set mydoc=Server.CreateObject("Microsoft.XMLDOM")
              mydoc.async=false
              mydoc.load(Request)
              Response.ContentType = "text/xml"
              if mydoc.parseError.errorcode<>0 then
              Response.write "<prob name='fail'>blah</prob>"
              else
              Response.write "<prob name='works'>yay</prob>"
              end if


              The asp script always sends <prob name='fail'>blah</prob> back to flex meaning that the xml failed to parse correctly. The xml is correct, if I load the same xml from a text file it will parse correctly, it only fails when the xml is loaded from flex.

              Does anyone know the exact format that the xml is sent in using the httpservice.send() method? I tried using Request.Form in ASP but it only gives the error printed at the bottom of this post.

              BTW is there anyway to get flex to trace error messages given from ASP when a script fails as I can't read them in a browser (because the request is sent using POST). When ASP gives an error flex either does not respond or gives this error which does not help my cause.

              (mx.messaging.messages::ErrorMessage)#0
              body = (Object)#1
              clientId = "DirectHTTPChannel0"
              correlationId = "39CFBD08-1AEC-89B8-EECA-57F7BC922158"
              destination = ""
              extendedData = (null)
              faultCode = "Server.Error.Request"
              faultDetail = "Error: [IOErrorEvent type="ioError" bubbles=false cancelable=false eventPhase=2 text="Error #2032: Stream Error. URL: http://127.0.0.1/test.asp" URL: http://127.0.0.1/test.asp"
              faultString = "HTTP request error"
              headers = (Object)#2
              messageId = "3AC23FB2-BFB0-AC27-AE06-57F7BCC14B44"
              rootCause = (flash.events::IOErrorEvent)#3
              bubbles = false
              cancelable = false
              currentTarget = (flash.net::URLLoader)#4
              bytesLoaded = 0
              bytesTotal = 0
              data = (null)
              dataFormat = "text"
              eventPhase = 2
              target = (flash.net::URLLoader)#4
              text = "Error #2032: Stream Error. URL: http://127.0.0.1/test.asp"
              type = "ioError"
              timestamp = 0
              timeToLive = 0




              EDIT:

              I wrote the value of the ASP request (sent from flex) to a text file and I ended up getting blank, in other words no XML. Now i'm not even sure if flex is sending any xml.
              • 4. Re: XML-RPC via HTTPService
                Blue_Pixel Level 1
                I have the same problem, I sometimes recieve that error #2032 too...and I don't know why because sometimes works (the same code).
                Tudor
                • 5. Re: XML-RPC via HTTPService
                  batmitra Level 1
                  Hi
                  1st - Tom, i'm not used to work with XML-RPC ,i use asp.net on my work, but in your case, the relation between the
                  request tag and the resulting httprequest is a XML tag, let me give an example:
                  if you have this:

                  <mx:request>
                  <name> myname </name>
                  </mx:request>

                  What you're saying to the http is to send an xml tag wich is a value/pair "<name>myname</name> like you would do in a query for instance mypage.aspx?name=myname, but the diference here is that you are sending xml thru http, so on your server side you must read xml tag coming from http stream channel , read it node value and process it, then you have to answer in the same mode, meaning you must build an xml document on your server side and send it on http stream channel. It's all about getting xml from one side to the other.

                  I hope you understand, or put here some code and i'll try to help, if you want i can either give you an example of how i do it on .net.

                  2nd - Ria Flasher , you have some problems, i'm not an asp programmer, i've jumped wright to asp.net wich is very easy to deal with xml. You problem starts with the request.resultformat, if you are using httpservice, you should leave this tag out, because probably if you delete it and debug your flex application you will notice that asp is returning an object and not text, you could use the xml or the e4x format of result, because in the end all you want is the xml. The request tag, i prefer to use it in mxml is so much easier, and it goes like this:

                  <mx:request>
                  <test>testxml</test>
                  </mx:request>

                  you are using it in code and i'm not sure if you need the xml declaration there, ill take a look at that.

                  3rd- Blue pixel, let'see some code to see where the problem might bee