Welcome, Guest
  • Author Topic: Passing out paramters from .Net webservice to Flash mx 2004 pro  (Read 3610 times)

    Aalok

    • Server what's that
    • *
    • Posts: 4
    • C++ developer
      • View Profile
      • Email
    Hello all I am new at Flash-db abd really hoping that experts here can help me with a probelm I have.

    I have a very simple C# .Net web service that has the following method

    [WebMethod]
    public string Test(out string p1, out string p2)
    {
         p1 = "test1";
         p2 = "test2";
         return "test3";
    }

    And I call it from the action script like follows: [in the 1st frame of my
    test.fla I have following code]

    stop();
    import mx.services.*;
    trace("Creating webservice");
    var myWebServiceObject = new
    WebService("http://localhost/TestWebService/TestWebService.asmx?WSDL");
    myWebServiceObject.onLoad = function (WSDLDocument)
    {
       trace("Wsdl load Complete");
       var s1:String;
       var s2:String;
       trace("making the test call");  
      MyPendingCallObject = myWebServiceObject.Test(s1,s2);
      MyPendingCallObject.onResult = function(result)
      {
         trace("Test call retunred successsfully"); // I see this trace
         trace("result = "+result); // I see result = test3 which is return value of the webservice
         trace(this.getOutputParameters().length); // displays "1"
     }
    }
    myWebServiceObject.onFault = function (fault)
    {
     trace("Wsdl load fault");
    }


    My question is why is this.getOutputParameters().length is 1 ? I was expecting
    it to be 3. How can I get the values of out paramters p1 and p2 ?

    Accroding to the documentation I should have been able to retrive these values
    using  PendingCall.getOutputParameterByName() and PendingCall.getOutputParameter()
    functions.

    I saw an article at Flash-db here at flash-db by Jeffrey Hill. It comes close to what I want to do. Could Jeffery please tell me how the "results" in WebServices in flash shows up as a structure. For my web service it simply says results and when I try to access p1 and p2 as members it comes out as undefined.

    Please someone help.

    --Aalok.

    Ronald Wernecke

    • Global Moderator
    • Systems Administrator
    • *****
    • Posts: 6203
      • View Profile
      • Professional Support
      • Email
    Hi Aalok,
    why do you expect something, which is not returned ;)

    If you want to see something in the results, you better return it there ;)

    All you return is the string "test3", which, as you realized, is received by your film.

    If you want to return more, put it into an array, or send a XML-String back, so that flash can work with it.
    happy flashing
    8)
    Ronald

    Aalok

    • Server what's that
    • *
    • Posts: 4
    • C++ developer
      • View Profile
      • Email
    Hello Ronald thank you for your reply.

    p1 and p2 are also "out-parameters" and returned back from the web service.
    If I trace out the pending call response I get the following :


    SOAP-Reponse: <?xml version="1.0" encoding="utf-8"?><soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><soap:Body><TestResponse xmlns="http://tempuri.org/"><TestResult>Test3</TestResult><p1>Test1</p1><p2>Test2</p2></TestResponse></soap:Body></soap:Envelope>


    Notice that in the <TestResponse> I have TestResult, p1 and p2. How do I access these using the results or something without having to parse the response XML ?

    I was under impression that MX 2004 pro should make all the soap handing and XML parsing seemeless. Is there something I am missing in the documentation ? or I have to parse this response ?

    -Aalok
    « Last Edit: 03/07/04, 08:29 by Aalok »

    Ronald Wernecke

    • Global Moderator
    • Systems Administrator
    • *****
    • Posts: 6203
      • View Profile
      • Professional Support
      • Email
    Hi,
    you can receive XML-Streams into the XML-Object.
    And then you can walk through the XML-Tree.
    Or, if you know the structure in advance, you can use the XML-Connector.

    There are som good examples at the macromedia site.
    happy flashing
    8)
    Ronald

    Aalok

    • Server what's that
    • *
    • Posts: 4
    • C++ developer
      • View Profile
      • Email
    Thank you for your replies Ronald. I am new to Flash-db. I have tried to find my solution on many places but Flash-db is only place I found "alive" :D.

    Looks like I will have to use XML-Object in order to parse the response packet. It seems that there is bug in PendingCall of WebService classes since the documentation says,

    [Page 584 of Using_Components.PDF]
    "The PendingCall object also offers you access to output parameters when there are more than one. Many web services return only a single result, but some web services return more than one result. The “return value” referred to in this API is simply the first (or only) result. The
    PendingCall.getOuptutXXX functions give you access to all of the results, not just the first. So
    while the “return value” is handed to you in the argument to the onResult() callback, if there are other output parameters you want to access, use getOutputValues() (returns an Array) and getOutputValue(index) (returns an individual one) to get the ActionScript decoded values."

    But as I demonstrated it does not work this way.  Looks like due to a bug the tag <TestResult> (<MethodResult>) is parsed instead of <TestResponse> (<MethodResponse>)

    I hope macromedia takes notice of it and fixes it in the neat future. Unfortunately there customer service sucks, they have not replied to my questions in more than 4 days.

    Nevertheless, I am happy to find flash-db, I will try to contribute as much as I can.

    Thanks again for your time.
    --Aalok.

    Ronald Wernecke

    • Global Moderator
    • Systems Administrator
    • *****
    • Posts: 6203
      • View Profile
      • Professional Support
      • Email
    Hi,
    it is not more results, it is one resulöt you receive, but the result is a XML-Structure.
    But it is one Textstream.
    happy flashing
    8)
    Ronald

    Aalok

    • Server what's that
    • *
    • Posts: 4
    • C++ developer
      • View Profile
      • Email
    Hello,

    I finally got the answer to my question and here it is.

    When I was Reading the documentation once again of "PendingCall.getOutputParameter()" I noticed the reference to SOAP RPC.


    [Page 586 Using_Components.pdf]
    "Description
    Function; gets an additional output parameter of the SOAPParameter object, which contains the value and the XML element. SOAP RPC calls may return multiple output parameters. The first (or only) return value is always handed to you in the results argument of the onResult()
    callback, but to get access to the others you need to use functions such as this one or getOutputValue(). The getOutputParameter() function returns the nth output parameter as
    a SOAPParameter object."

    There was no mention of SOAP RPC in the previous paragraph I Posted. Anyway, when I made my web service call as Soap RPC call, as follows

    [WebMethod]
    [SoapRpcMethod]
    public string Test(out string p1, out string p2)
    {
     p1 = "Test1";
     p2 = "Test2";
     return "Test3";
    }

    Everything in flash started to work fine. The this.getOutputParameters().length returned "3" and I could read the values of p1 and p2 by doing,

    for (i = 0; i < this.getOutputParameters().length; i++)
    {
     trace(this.getOutputParameter(i).value);
    }

    Thanks for your time Ronald, and I hope my posting here will help someone else.

    --Aalok.

    Ronald Wernecke

    • Global Moderator
    • Systems Administrator
    • *****
    • Posts: 6203
      • View Profile
      • Professional Support
      • Email
    Thank you for this posted answer.
    This is what makes the difference in this board ;)
    happy flashing
    8)
    Ronald

    rstackhouse

    • Server what's that
    • *
    • Posts: 6
      • View Profile
    Does anyone have any idea how to handle arrays using the webservice classes?

    I have made a .NET webservice that returns an array of strings like so:

    <?xml version="1.0" encoding="utf-8"?>
    <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:tns="http://tempuri.org/" xmlns:types="http://tempuri.org/encodedTypes" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
    <soap:Body soap:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
    <tns:getEventsResponse><getEventsResult href="#id1" /></tns:getEventsResponse>
    <soapenc:Array id="id1" soapenc:arrayType="xsd:string[8]">
    <Item>14|2/7/2006 7:00:00 PM|General|Langford C 307|We will discuss the proposed compositing project for submission to the Saw &apos;Em Off ShortsFest</Item>
    <Item>15|5/5/2006 7:00:00 PM|General|Rudder Theater|Saw &apos;Em Off Shorts Fest</Item>
    <Item>16|2/14/2006 7:00:00 PM|General|Langford C 307|Ideas and Storyboards for compositing project are due.  We will cast a vote on which idea we would like to explore.  We will also talk about PSAs for the Open Access Labs.</Item>
    <Item>17|2/21/2006 7:00:00 PM|General|Langford C414|Review of ideas for short film project, and disscusion of Open Access Lab Screen Savers</Item>
    <Item>18|2/28/2006 7:00:00 PM|General|Halbouty 260|Tour of the Immersive Visualization Center</Item>
    <Item>19|3/3/2006 4:00:00 PM|General|Langford B 102|ILM Tutorial: Digital Creatures</Item>
    <Item>20|4/15/2006 7:00:00 PM|General||Early Deadline for Shorts Contest</Item>
    <Item>21|5/1/2006 7:00:00 PM|General||Deadline for Shorts Contest</Item>
    </soapenc:Array>
    </soap:Body>
    </soap:Envelope>

    but these lines

    var resultArray:Array = _root.calendarResultObj.getOutputValues();
          
    trace("length: "+resultArray.length);


    prints "length: undefined" in the debug panel, even though this line

    trace("result: "+result);

    yields this

    result: 14|2/7/2006 7:00:00 PM|General|Langford C 307|We will discuss the proposed compositing project for submission to the Saw 'Em Off Shorts Fest,15|5/5/2006 7:00:00 PM|General|Rudder Theater|Saw 'Em Off Shorts Fest,16|2/14/2006 7:00:00 PM|General|Langford C 307|Ideas and Storyboards for compositing project are due.  We will cast a vote on which idea we would like to explore.  We will also talk about PSAs for the Open Access Labs.,17|2/21/2006 7:00:00 PM|General|Langford C414|Review of ideas for short film project, and disscusion of Open Access Lab Screen Savers,18|2/28/2006 7:00:00 PM|General|Halbouty 260|Tour of the Immersive Visualization Center,19|3/3/2006 4:00:00 PM|General|Langford B 102|ILM Tutorial: Digital Creatures,20|4/15/2006 7:00:00 PM|General||Early Deadline for Shorts Contest,21|5/1/2006 7:00:00 PM|General||Deadline for Shorts Contest

    would someone please tell me what I am doing wrong.

    Thanks

    Robert

    Jorge Solis

    • Global Moderator
    • Systems Administrator
    • *****
    • Posts: 14616
      • View Profile
    Because you get a string, not an array. You can split using | , since seems to be the character used for separate text.

    Jorge

    rstackhouse

    • Server what's that
    • *
    • Posts: 6
      • View Profile
    Thanks for the input.

    Is there a way to receive an array from a webservice in Flash?  Or would I be better off receiving a structured xml document and parsing it out as an array?

    If you notice, each item in the array

    <Item>14|2/7/2006 7:00:00 PM|General|Langford C 307|We will discuss the proposed compositing project for submission to the Saw &apos;Em Off ShortsFest</Item>

    is a delimited string using "|".  This is because .NET doesn't support returning multi-D arrays.  I am creating a calendar application, and I need to be able to force all of this information into a multi-D array when the calendar movie is initialized.  For each date that has an event, there is a date, meeting type, location, and description.

    Any help on this matter would be greatly apprecitated.

    Thanks

    Robert

    Ronald Wernecke

    • Global Moderator
    • Systems Administrator
    • *****
    • Posts: 6203
      • View Profile
      • Professional Support
      • Email
    These Parameters are not in the reurn statement ;)

    If you want to receive info, your function has to return them
    happy flashing
    8)
    Ronald

    rstackhouse

    • Server what's that
    • *
    • Posts: 6
      • View Profile
    I am afraid your explanation is a little vague.

    I opened the webservice panel in flash and input the url for the webservice. It showed the webservice return type as an array, but I am not getting one.  If I try PendingCall.getOutputParameters(), I get nothing.

    What I was talking about above is getting each one of the <item> tags in the SOAP Respsonse mapped over to an index of an array.

    Say for example you have something like ...<item>1</item><item>2</item>...

    Then the corresponding array should look like myArray[0] = 1 and myArray[1] = 2.

    Ronald Wernecke

    • Global Moderator
    • Systems Administrator
    • *****
    • Posts: 6203
      • View Profile
      • Professional Support
      • Email
    As Jorge allready mentioned - you do not receive an array - it is a string.

    Split the string first with the delimiter "," (comma) to split it into the items, and then with the delimiter "|" (upright line) to split the elements of the items.
    Then you have an array of arrays, which can structural be addressed.
    happy flashing
    8)
    Ronald

    rstackhouse

    • Server what's that
    • *
    • Posts: 6
      • View Profile
    Thanks for the insight.  I didn't see the commas. I don't mean to sound thick here fellas, and I don't mean to sound disrepectful either because I know I'm a newb here on the board.

    I put the pipe, "|", in the strings on purpose so I could do exactly what you said, split the strings there.  I was expecting to have to do this.  What I didn't expect to have to do was to split the return value at the commas. 

    What I need to know is why I got a string back instead of an array.  Is this just how Flash handles arrays?  Did I miss a function call somewhere? And just to restate so you gents don't think I'm a complete idiot:

    1. The return type of the webservice I am calling, the one I built in .NET, is string[].

    2. Under the Web Service Development panel in Flash, this is shown for my webservice, "<-results: ArrayOfString(Array)[optional]"

    That last bit looks to me like I ought to just be able to call PendingCall.getOuputParameters() or getOutputValues() and assign it to an array and then move on to creating a multidimensional array from there by spliting the indexes of the array I just got at the "|".