Consuming Web Services in ASP.Net
Web services have quickly become the most touted industry buzzword. The fact that they are based on XML and other "Internet" standards make it the ideal vehicle to send and recieve information between applications. Dreamweaver MX has taken this into consideration and given you the power to consume web services in a visual environment.
When a web service is published, it will also have a WSDL (
Web
Service
Definition
Language) file along with it. This gives applications wanting to use it some meta-data concerning the service such as what are the method names, how many parameters it takes, and other useful tidbits of information. By feeding Dreamweaver the URL of this WSDL file, you give it the information it needs to create what's called a proxy class. This is a .Net assembly (.dll) that hides all of the intricate details involved in calling the web service over the internet. Behind the scenes, this is done with the WSDL command line utility that is installed with the .Net SDK.
The first step in consuming a web service involves finding a web service to consume. Several web sites exists solely for this reason:
- Sal Central
- XMethods
- Microsoft UDDI
Once you have found one you are interested in consuming, find the link the WSDL file. For this tutorial, we will be consuming the GEO Cash ATM Lookup web service. With this service, we can find ATM locations in any US city by entering in a zip code.
Once you have found the service you wish to consume, you can create the proxy class for it by going to the
Application panel and choosing the
Components tab.
When you click on the + icon, choose
Add using WSDL. This will bring up the following dialog.
Enter the WSDL URL and Dreamweaver will create two files in your site root, a .dll file which must be moved and uploaded to the
/bin directory, and a .cs file with the source for the .dll in case you want to take a peek below the hood. Another look at the Components panel will reveal a tree view of available methods in the .dll.
Once all of this is registered, you are ready to create your web form. Begin by creating a new .aspx file either from
File > New dialog, or right clicking in the site window and choosing
New File.
Create the web form by following these steps:
- Add a form from the Form object panel
- Enter code view and change the opening form tag to look like this:
<form runat="server"> - From the ASP.Net Object panel, insert a TextBox with the ID of zip.
- Next, insert an ASP.Net button with the id of submit
- After adding the button id, go the Event > OnClick option in the tag editor and add the text "submit_click"
- Add a simple ASP.Net label with the id result
Once all of this has been done, your web form should look like this:
The final step, is to add the code that will process the GEOCash servic