Consuming Web Services Video Highlights
Evaluate Visual Studio
Web services allow Web pages to access distributed applications. By offering both access to information and application functionality as a service, Web services can be delivered and paid for as streams of services that allow universal access from any platform. In this video, we’ll address Web service support for Dreamweaver Version 8 and Visual Studio 2005. The Web page that connects to the Web service is commonly known as a consumer, and the service itself is known as a publisher. Dreamweaver 8 lets you create pages and sites that are consumers of Web services.
Dreamweaver currently supports the creation of Web service consumers using Macromedia ColdFusion MX, ASP.NET, and Java Server Pages (JSP). To generate the proxy classes necessary for ASP.NET pages to consume Web services, you must have the .NET Framework SDK installed on the system. Another prerequisite is that specific executables be referenced in the path environment variable. The environment variables can be modified from the System icon in the Control Panel, then under the Advanced tab, and finally, Environment Variables. Dreamweaver needs to be able to reference that path to the C# and Visual Basic command-line compilers, as well as to the program WSDL.EXE. The WSDL.EXE proxy generator creates a compiled component that the server side code uses to communicate with the Web service publisher. The Web service proxy is generated from an XML document, stored in the Web Service Description Language. Here is the executable that makes the proxy.
With these prerequisites in place, you can now start the Dreamweaver application. As part of the video, you will see how to search for an appropriate Web service, generate the proxy, and consume the service through that proxy. To get started, create a new ASPX page. Now it’s time to find an appropriate Web service. In the Application panel select the "Components" tab and using the "plus" button, select "Add using WSDL". It is possible to browse available services on the xMethods site, which is called a Universal Description, Discovery, and Integration register, or UDDI. Listed on the site are many public services available for use either for free or for a fee. Here is one called on the list called "Phone Notify." It is designed to place a call and use a voice synthesizer to speak the text you want it to say to the person you are calling.
After finding an appropriate service, the URI to that Web Service Description language file, or WSDL, needs to be entered. This process generates a proxy for the server-side code to use. Dreamweaver then shows the available properties and methods in the Components panel. These can be dragged onto the code surface to have sample code written that references the Web service. But before we do this, we need to establish some server controls to provide parameters to be used when calling the Web service. First a text box for the phone number to dial, and another button for the message to be spoken, also a button to submit the request over to the server. So that these controls don’t run together on the same line on the page, formatting can be applied with tags. These controls need to be placed within a form element with the attribute runat="server." At the top of the file, an inline script block will be used for the code that will run on the server. An event handler for the button’s click event comes first; this must be coded by hand. In here is where the logic for the Web service can be placed. By dragging in the constructor of the PhoneNotify service, a statement to instantiate the Web service proxy object is built.
Also dragging in the method "NotifyPhoneBasic", creates a sample line that performs the actual call to the Web service. To complete the solution, we will need to add in values for the six string variables that are listed. There is no assistance given through Code Hints or other means to know what these six parameters are, so we have to refer to the WSDL or some other documentation to know what values they should hold. This WSDL document describes all the properties and methods available from the Web service. In this case, scroll down to find the NotifyphoneBasic method. Here we determined the proper sequence of parameters. It is PhoneNumberToDial, TextToSay, then CallerID, CallerIDname, VoiceID, and LicenseKey. Making note of that, it’s now time to go back into the code and fill in these parameters. The text that’s submitted in the text box will be used for both phoneNumber to dial and textToSay, then a bogus number for the caller ID, a blank Caller ID name, a voice ID of "1," and no license key. To wire up the button’s event handler, you need to add in a Page_Init handler, and in here use an AddHandler statement to wire up the button’s click event.
With these pieces in place, it is now time to deploy the generated proxy class to the Web server. This is done by clicking the button with the green arrow pointing upwards, which deploys necessary files to the Web server. By default, the tool deploys to the top folder in the project, but for this, which is a compiled assembly, the path must be changed to lead to the "bin" folder. The listing of files deployed includes the proxy class called "PhoneNotify.dll" and also standard Dreamweaver control library, which is not used in this project. Now it is possible to test the resulting page and see that indeed entering a phone number, and then a line of text, and then finally clicking the button will queue the call. Soon my phone will ring—(Call is accepted)—and the message entered is now spoken via a voice synthesizer. (Message)
Web services offer a great way to use a variety of resources from across the Internet.
Visual Studio 2005 Section
Consuming a Web Service in Visual Studio is very straightforward. There is no need to modify any special pathing or install any additional software. In Solution Explorer, reference the context menu of the project and select "Add Web Reference." You can then enter a URI reference to the WSDL of the Web service you wish to use. The methods of all Web services described in the WSDL are listed in the Description panel. If you are satisfied with the results, select "Add Reference," which will generate the proxy class used to make calls into the Web service.
On the design surface of the Web form we’ll be adding the same two textboxes to hold the phone number and message, and also a button to enact the call to the Web service.
The click event of the button will hold the code that consumes the Web service. First, you need to instantiate an object to refer to the proxy. In this case, it is called myPhoneNotify. Then, using that object, the Web service can be called. We get nice descriptive names for the six string properties required by the service from Intellisense.
Now that these few lines of code have been written, the site is ready for testing. Running the page, we see the same functionality available—(Accepts incoming call)—and the phone call successfully placed through the service. (Message)
Web service calls can take some time to complete because they are dependant on a network call generally placed across the Internet. For this reason, in highly performing Web sites, it is useful to make these calls asynchronously, meaning that while the call is being placed, other activity such as database access, can be performed. It is possible to create this kind of code in both Dreamweaver and Visual Studio, but the programming experience in Visual Studio is enhanced with Intellisense, and other tools including debugging, to more easily create the logic required by high-performance Web sites.
This video covered Web service support for Dreamweaver Version 8 and Visual Studio 2005.