How to get the return value(array type) of a webservice method in ASP

Discussion in 'ASP General' started by Ocean, Feb 6, 2006.

  1. Ocean

    Ocean Guest

    I'm a novice on ASP using VBScript, and I encountered a problem when I
    want to get and use a return value of a web method in my ASP code.

    There is a web method called "getQuote", which takes a string
    indicating the symbols as its parameter, and return an array of
    "BTQuote" objects which contain the info of every symbol respectively.

    Also, there is a proxy object which is generated automatically by the
    IDE. This proxy object is wrapped as a COM tlb and deployed on the
    server, correctly, i'm sure.

    I want to write ASP code to get the returned "BTQuote" array so that I
    can show the information, can anybody tell me how to do that ?

    ps, I've already written the following code to initiate a service
    object, it worked fine:
    Set btService = Server.CreateObject("BTLib.BTDemoService")
    ////////How do I get this return value? = btService.getQuote("bidu")

    Any suggestion must be appreciated.
     
    Ocean, Feb 6, 2006
    #1
    1. Advertising

  2. Something like this:-

    Dim aoBTQuote
    Dim oBTQuote

    aoBTQuote = btService.getQuote("bidu")

    For Each oBTQuote In aoBTQuote
    'do stuff with oBTQuote
    Next


    Anthony.
     
    Anthony Jones, Feb 6, 2006
    #2
    1. Advertising

  3. Ocean

    Ocean Guest

    Re: How to get the return value(array type) of a webservice method in ASP

    Hi, it threw out a error.
    Error Type:
    Microsoft VBScript runtime (0x800A000D)
    Type mismatch

    in this line: For Each oBTQuote In aoBTQuote

    and by using Response.write typename(aoBTQuote), I get unknown() type.

    does that mean I cannot get the array typed return value?

    thanks

    Johnson
     
    Ocean, Feb 7, 2006
    #3
  4. Ocean

    Ocean Guest

    Re: How to get the return value(array type) of a webservice method in ASP

    I make another test by change the return type of my web method to
    BTQuote, and my asp code as follows

    Dim oBTQuote
    Set btService = Server.CreateObject("BTLib2.BTDemoService")
    oBTQuote = btService.GetQuote("bidu")
    Response.write typename(oBTQuote)
    Response.write oBTQuote

    The result is shown as:
    String
    BTLib2.BTQuote

    I don't know why this happens, the method must return a BTQuote value,
    but instead, it returns a string which indicates the actual type of the
    return value, anyone know why? thank

    Ocean
     
    Ocean, Feb 7, 2006
    #4
  5. Ocean

    Ocean Guest

    Re: How to get the return value(array type) of a webservice method in ASP

    It worked if I changed the third line to
    Set oBTQuote = btService.GetQuote("bidu") !!!!!

    But still got problem when return an array of BTQuote, the typename()
    still get Unknown() :(
     
    Ocean, Feb 7, 2006
    #5
  6. Ocean

    Ocean Guest

    Re: How to get the return value(array type) of a webservice method in ASP

    It worked if I changed the third line to
    Set oBTQuote = btService.GetQuote("bidu") !!!!!


    But still got problem when return an array of BTQuote, the typename()
    still get Unknown() :(

    Ocean
     
    Ocean, Feb 7, 2006
    #6
  7. Ocean

    Ocean Guest

    Re: How to get the return value(array type) of a webservice method in ASP

    Here is another test I've made. I encapsulate the array of BTQuote into
    the BTResult class, then changed the return type to BTResult.

    by running following code,
    Set btService = Server.CreateObject("BTLib4.BTDemoService")
    Set oBTResult = btService.GetQuote("bidu")
    Response.write typename(oBTResult.btquotes) // the btquotes field
    contains the array

    I got
    Object()

    is this normal? shouldn't it be Variant()?
    thanks

    Ocean
     
    Ocean, Feb 7, 2006
    #7
  8. Ocean

    Ocean Guest

    Re: How to get the return value(array type) of a webservice method in ASP

    ps, by change the code to
    Response.write IsArray(oBTResult.btquotes)

    i got "true" !!! but how can I access it as a array? using for loop, it
    threw out a type mismatch error
     
    Ocean, Feb 7, 2006
    #8
  9. Re: How to get the return value(array type) of a webservice method in ASP

    Can you use VarType() on the array instead. What value do you get?

    Can you loop through the array like this:-

    Dim i

    For i = LBound(aoBTQuote) to UBound(aoBTQuote)
    Set oBTQuote = aoBtQuote(i)
    ' Do stuff
    Next
     
    Anthony Jones, Feb 7, 2006
    #9
  10. Ocean

    Ocean Guest

    Re: How to get the return value(array type) of a webservice method in ASP

    Hi, Anthony
    VarType() returns 8201 which indicates it is an array, by the way, I
    can get its ubound also.

    But I can't access the element in the array by any approach, which
    nearly drives me nuts.
    your suggestion seems to work, but it still will crash at
    "aoBtQuote(i)", cuz I cannot use this way to access the element, it
    will throw a type mismatch error.

    I got some reference here:
    http://support.microsoft.com/kb/q174576/
    http://www.dotnet247.com/247reference/msgs/42/211620.aspx

    maybe they will help, but still don't know how to do, would you please
    give me some advice according to the refs? thank you very much,
    Anthony!!!

    Ocean
     
    Ocean, Feb 7, 2006
    #10
  11. Re: How to get the return value(array type) of a webservice method in ASP

    Yes it does look like you should follow the advice of the Q174576.

    The vartype of the array indicates that it is an array of objects.

    So try making the return type of the method a variant and have the array
    returned by an array of variants.

    Anthony.
     
    Anthony Jones, Feb 7, 2006
    #11
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Charles
    Replies:
    6
    Views:
    14,058
  2. DaKoadMunky
    Replies:
    8
    Views:
    3,338
    Leor Zolman
    May 14, 2004
  3. Greenhorn
    Replies:
    15
    Views:
    885
    Keith Thompson
    Mar 6, 2005
  4. Jonathan
    Replies:
    4
    Views:
    2,197
    Steven Cheng [MSFT]
    Jul 9, 2008
  5. Paul

    Get return value from an asp.net webservice..

    Paul, Aug 12, 2008, in forum: ASP .Net Web Services
    Replies:
    3
    Views:
    357
    John Saunders
    Aug 13, 2008
Loading...

Share This Page