The Data Sources Window in Visual Studio 2005 allows you to drag and drop data sources onto a form to generate all of the controls and components needed to use that data source for databinding. The Data Sources Window support binding to databases, Web Services, and custom objects.
The Web Services piece is still a little quirky in Beta 1 because they wisely chose to only let you bind to public properties on an object definition, not public fields. This will hopefully discourage the definition of public fields to expose data from a class, which is a bad idea all around. However, the current client proxy code that gets generated for a Web Service when you create a Web Reference just exposes public fields on the classes generated for objects returned from a Web Service. Thus the Data Sources Window in Beta 1 won’t let you see any of the members on the object types returned from the Web Service.
The good news is that the wsdl.exe tool that ships with the .NET 2.0 SDK does in fact create public properties to wrap the members on the objects returned by a web service. So there is a fairly straightforward workaround to get Web Services working with the Data Sources window in Beta 1, detailed below.
- Go through the Add Data Source wizard, select Web Reference as the type of Data Source, and point it at the WSDL URL for the data source. For example, you would point it at the Amazon Web Service at:
After completing the wizard, go check what the namespace is for the generated web procy file. To do this, you need to select Show All Files in Solution Explorer, and drill down to the Reference.cs file that was created under the Web References node for the Web Service. For the example above, that would be
Fire up a Visual Studio 2005 command prompt window, and run wsdl.exe with the wsdl url, an out param to generate the Reference.cs file, and the namespace param to set the namespace from step 2. Example:
wsdl.exe http://soap.amazon.com/schemas3/AmazonWebServices.wsdl/out:Reference.cs /n:MyApp.com.amazon.soap
Copy the generated Reference.cs file (or vb if that is your flavor) into the WebServices subfolder created under your project where the existing Reference.cs created by the Add Web Reference process lives, overwriting the existing file. You should see that the file sizes are about double. That is because the wsdl.exe has property wrappers for all the fields that the Add Web Reference one just exposed publicly.
Close the Data Sources window. Then close Visual Studio. Then reopen your project in Visual Studio 2005 and reopen the Data Sources window.
you should now be able to drill down into the properties of the data source objects returned from the web methods of the web service, and if you drag them onto a form, proper UI will be generated.