Need help returning data from a vb.net webservice please

  • Thread starter Molalla Attenborough
  • Start date
M

Molalla Attenborough

My task seems simple: I want to create a vb.net webservice and consume it
with a client created in Macromedia FlashMX.

Let's get this out of the way - I don't want to use Coldfusion for data access.
I do not want to use vb.net to create my client interface. I want my service
to return a plain old array of complex types.

FlashMX doesn't work well with XML data serialized by returning a dataset
object from a public function in the service.

I have been trying to find a way to return the data from the service in a manner
that Flash can utilize. I have made some headway but I need a little more help.

Can anyone show me a way to return data from a vb.net webservice in a format
that is serialzed as an array of complex types? I would really appreciate it.

I don't need the code to fill datasets. I just need to know how to proceed from
there.

Thanks in advance!
 
J

Jan Tielens

You can create a class to store date, for example suppose you want to
retrieve Customer information:
Public Class Customer
Private _name As String
Private _email As String

Public Sub New(ByVal name As String, ByVal email As String)
Me.Name = name
Me.Email = email
End Sub

Public Property Name() As String
Get
Return _name
End Get
Set(ByVal value As String)
_name = value
End Set
End Property


Public Property Email() As String
Get
Return _email
End Get
Set(ByVal value As String)
_email = value
End Set
End Property
End Class

In your Webservice you can return an array of customer objects:
Dim a As New ArrayList

a.Add(New Customer("jan", "111"))
a.Add(New Customer("bill", "222"))

Return a.ToArray(GetType(Customer))
 
M

Molalla Attenborough

Jan Tielens said:
You can create a class to store date, for example suppose you want to
retrieve Customer information:
Public Class Customer
Private _name As String
Private _email As String

Public Sub New(ByVal name As String, ByVal email As String)
Me.Name = name
Me.Email = email
End Sub

Public Property Name() As String
Get
Return _name
End Get
Set(ByVal value As String)
_name = value
End Set
End Property


Public Property Email() As String
Get
Return _email
End Get
Set(ByVal value As String)
_email = value
End Set
End Property
End Class

In your Webservice you can return an array of customer objects:
Dim a As New ArrayList

a.Add(New Customer("jan", "111"))
a.Add(New Customer("bill", "222"))

Return a.ToArray(GetType(Customer))

--
Greetz,
Jan
__________________________________
Read my weblog: http://weblogs.asp.net/jan

This is about as close as I have been able to get. I have been working with the
arraylist. the problem is that it causes the serializer to choke. I get error messages
telling me to add XmlIncludes etc. It is the specifics and not the generalizations
that I am stuck on. Your example causes the same problems for me.

I appreciate your help. Do you know the proper syntax for declaring a Class
with the correct xmlelement etc tags to get through the serializer?

TIA
 
J

Jan Tielens

The ArrayList is not strongly types, so it does not serialize well (without
including the XMLInclude attributes). So it's better to return a strongly
types list like an array. Did you try the return statement as in my example?
Make sure you use the ToArray method.
Return a.ToArray(GetType(Customer))

If you really want to work with the ArrayList, let me know; I'll lookup the
syntax and try to make a quick example...
 
M

Molalla Attenborough

Jan Tielens said:
You can create a class to store date, for example suppose you want to
retrieve Customer information:
In your Webservice you can return an array of customer objects:
Dim a As New ArrayList

a.Add(New Customer("jan", "111"))
a.Add(New Customer("bill", "222"))

Return a.ToArray(GetType(Customer))

This is the part that I am stuck on.
Do I return it as an array?
As in:

<WebMethod()> Public Function GetArray() as array
Dim a As New ArrayList

a.Add(New Customer("jan", "111"))
a.Add(New Customer("bill", "222"))

Return a.ToArray(GetType(Customer))

I am getting an error when I try to do this that says
You must implement a default accessor on system.array because it inherits from
ICollection.

I feel like I am close but I still can't get it to work.
 
M

Molalla Attenborough

Molalla Attenborough said:
This is the part that I am stuck on.
Do I return it as an array?
As in:

<WebMethod()> Public Function GetArray() as array
Dim a As New ArrayList

a.Add(New Customer("jan", "111"))
a.Add(New Customer("bill", "222"))

Return a.ToArray(GetType(Customer))

I am getting an error when I try to do this that says
You must implement a default accessor on system.array because it inherits from
ICollection.

I feel like I am close but I still can't get it to work.

Hold the press! I think a lightbulb went on!
I guess I should return it as an array of Customer...

As in
<WebMethod()> Public Function GetArray() as Customer()
Dim a As New ArrayList

a.Add(New Customer("jan", "111"))
a.Add(New Customer("bill", "222"))

Return a.ToArray(GetType(Customer))
 
P

Patrick Wenzel

Do you have Macromedia Flash Remoting? Which version of
Flash are you using? Flash MX 2004 Professional is
supposed to allow Flash clients to consume web services
from .Net (thought I haven't tried it), stherwise it is
much easier to consume a .Net web service if you have the
Flash Remoting software.

I have a simple demo of a Flash MX client to a .Net web
service. You can view it at:

http://www.infoscico.com/FlashWebService/DbService.html

I can send you the code if you would like to see it.
It's passing data to the Flash Client in a DataSet, which
is a useful way of passing complex data. It's not
perfect. I couldn't find a way to pass a DataSet back to
the web service.
 

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

Forum statistics

Threads
473,769
Messages
2,569,578
Members
45,052
Latest member
LucyCarper

Latest Threads

Top