How to return a custom object to the client application?

ProgMan

Well-known member
Joined
Nov 25, 2006
Messages
55
Location
UK
Programming Experience
3-5
Hello again :)

I have a question which is supposed to be simple but I can't seem to get it right :(


I have a web service (vb.net using visual studio 2005) with a method named getinfo(). I also created a class (Person) that has three attributes (fName, lName and DOB).

Now, the method getinfo() is used to retrieve data from a database and it returns the class Person. When I run the web service from the browser and invoke the getinfo() method, it correctly displays the returned data (e.g. fNAme, lName, DOB).

However, I can't get the data in my client application (visual studio 2005). Normally, if a method returns String, we can write
VB.NET:
Dim str As String = webService.getinfo()
. But because the method in this case returns an object, the client cannot understand how to use this returned data. I tried to -
add a reference to the client application by adding the original Person class and then declare a variable of that class type, created a similar class with the same attributes on the client side but nothing seems to work.

Can anyone help me on this please? This is getting really annoying now :mad:

N.B. Please feel free to ask questions if my problem description is not good enough!
 
The return type is WebserviceNamespace.Person. When you created your ws instance you perhaps did Dim webService As New wsns.Service in which case the Person would be declared Dim p As wsns.Person
 
Thanks JohnH for your kind reply (as usual :) )

My application is working now. However, the code is a lil different and I'm not sure why that is. Below is the code -
VB.NET:
        Dim ws As New localhost.Service()
        Dim p As localhost.Person [COLOR="Red"]'Note that, I have to use localhost here not ws ![/COLOR]
        p = ws.getInfo()
        Label1.Text = p.fname
        Label2.Text = p.lname
        Label3.Text = p.dob

Although its working now, I don't know why I have to use localhost instead of ws. Thats why I was stuck before.
 
"localhost" is the namespace to the web service proxy class that was generated when you discovered the (local machine) service in design time. If you had mapped a web service on the internet for example http://www.terraservice.net/TerraService2.asmx the namespace would be "net.terraservice.www" by default.

"ws" in your above code example is the name of a variable, and after assigned the reference to the service instance. You don't refer to a class type by a variable instance name.
 
I get it now. I didn't notice your example properly (Dim webService As New wsns.Service) and misread it :eek:

Anyway thanks again.

See you later :)
 
Back
Top