Using the WSDL Utility


The Web Services Description Language (WSDL) utility that comes with Visual Studio .NET is designed to reverse engineer a SOAP message into a class that can hold the information. For example, in the employee details case, you have a structure called structEmployee. And you can access the methods of this structure, but you do not have the structure. What if you want to use this in another part of your application? When the Web service reference is added to your application, the Integrated Development Environment (IDE) must somehow retrieve information about the objects that you will be passing to the Web service to create the proxy objects (the object definitions displayed in the object browser). For these and other reasons, you can turn to the WSDL utility.

Wsdl.exe is located in the \Microsoft Visual Studio .NET\FrameworkSDK\Bin folder (for version 1.0) or the \Microsoft Visual Studio .NET\SDK\v1.1\bin\ folder (for version 1.1). You need to run it from the command line or set it up as an external tool within the .NET Framework. For this example, add it as an external tool because you probably will not use it frequently, and if you have not set up an external tool before, now is a great time to learn. Select Tools External Tools from the VS IDE main menu. That brings up the External Tools dialog box, as shown in Figure 11-15.

click to expand
Figure 11-15: The External Tools dialog box

Click the Add button and enter information as shown in Table 11-2.

Table 11-2: The Wsdl External Tools Properties

Property

Value

Title

Wsdl

Command

(Path to the wsdl.exe file)

Arguments

/l:VB

Initial Directory

$(SolutionDir)

Prompt For Arguments

Checked

Once you have entered these values, click the OK button. The /l:VB entry for the argument specifies that the output should be formatted as a Visual Basic code file; the default is C#. You need to prompt for the arguments because you need to specify the location of the .wsdl file. If you look at the Tools menu again, you should see an entry for the Wsdl application. Clicking the Wsdl entry causes the dialog box in Figure 11-16 to appear.

click to expand
Figure 11-16: The Wsdl dialog box

At the end of the Arguments parameter, add http://localhost/northwind/service1.asmx?wsdl and then click the OK button. You will then see a command window appear briefly as the Service1.vb file is being written. Next, navigate to your solution folder and you will see this file. Double-click it to open it in the VS IDE. Take some time to examine it. The class created is all you need to call the service (as opposed to adding a Web reference as you did earlier). It creates a class called structEmployee (not a structure) and all of the methods to call both of your Web services—synchronously and asynchronously.

Tip

It does not matter if you use a structure or a class when you are dealing with XML serialization. As long as the class (or structure) name is the same as the original class or structure, and all of the public properties are identically named, you can deserialize a class object to a structure object and vice versa.

The real strength of this utility, combined with the awesome features of the .NET Framework, allows you to dynamically generate and compile code to call these Web services even if you know absolutely nothing about them!

Now that you have examined how to create and consume Web services, let's look at how you actually go about publishing them and finding other published Web services.




Building Client/Server Applications with VB. NET(c) An Example-Driven Approach
Building Client/Server Applications Under VB .NET: An Example-Driven Approach
ISBN: 1590590708
EAN: 2147483647
Year: 2005
Pages: 148
Authors: Jeff Levinson

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net