Retrieving datalist from webservice

mbf114

Member
Joined
Apr 14, 2003
Messages
11
Location
Pennsylvania
Hello all:
I have set up a webservice, created a dataset named dsCity, and can invoke it to return all cities and zips within my database on the server, but need direction in how to capture that dataset in a client application in a drop down box. Do I create another dataadapter in the client and reference the webservice dataset or is there another way of accomplishing this? I know the client can directly access the database but need it to access it through the webservice instead. I appreciate any help or direction you can provide. Thanks, Matt
 
Youll first need to add a webreference. In your project, right click on the References node (in the Solution Explorer) and select Add Web Reference. In the popup, put in your URL and press enter, then Add.

You should now see your webreference in your project. Id suggest renaming it - the default name is the base URL (so if the webservice is at http://www.microsoft.com/link then the name will be "www.microsoft.com"). Name it something like "MyWebService" or whatever makes sense.

Now in code, you can instantiate the webservice like any object, as in:
Code:
Dim ws As MyWebService = New MyWebService()
Dim ds As DataSet = ws.GetMyDataSet()

Now youre dataset is filled, no need to use a DataAdapter.

-Nerseus
 
I want to thank you for your help. I am sure that will work fine. As soon as I can configure VPN I will be able to test it and let you know.Thanks.---Matt
 
I forgot to mention an important fact:
When you add the reference to a web reference, .NET builds a proxy class for you. To see the source code (in case you want/need to make changes), youll have to click on the "Show All Files" toolbar button in Solution Explorer. Then expand the following:
Code:
Web References
  ->[i]WebServiceName[/i]
    ->Reference.map
      ->Reference.cs

Its the Reference.cs file that you want. It exposes all of the webservice methods as actual objects. It generates all of the messy SOAP code to instantiate and call a webservice.

Why is this important? Well, it could be important if your webservice returns a non-standard type, such as a class youve created yourself. Even if the type is referenced on the server and client, the proxy class will generate a new class definition. While it may look exactly like your local class, its technically a different class (in a different namespace). This may not affect you, but worth mentioning.

Also, if you ever get an error when calling a webservice, youre likely to see the green highlighted line in the proxy class, not in your "real" code. You may not know that this proxy class exists, so I mention it :)

-Nerseus
 
Back
Top