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

O

Ocean

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.
 
A

Anthony Jones

Something like this:-

Dim aoBTQuote
Dim oBTQuote

aoBTQuote = btService.getQuote("bidu")

For Each oBTQuote In aoBTQuote
'do stuff with oBTQuote
Next


Anthony.
 
O

Ocean

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
 
O

Ocean

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
 
O

Ocean

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() :(
 
O

Ocean

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
 
O

Ocean

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
 
O

Ocean

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
 
A

Anthony Jones

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
 
O

Ocean

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
 
A

Anthony Jones

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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,904
Latest member
HealthyVisionsCBDPrice

Latest Threads

Top