Walkthrough: Designing a Web Service
This walkthrough illustrates key aspects of designing a Web service using Application Designer in Visual Studio Team System Architecture Edition. This walkthrough explains how to:
Define operations on an existing Web service.
Implement the Web service.
Add an external Web service (a Web service outside the solution) and view Web methods on it.
Connect the external Web service to other applications.
This walkthrough builds on concepts presented in the introductory walkthrough topic, Walkthrough: Defining Applications on Application Diagrams.
To define operations on the Catalog Web service
Load the sample provided at http://go.microsoft.com/fwlink/?LinkId=40867.
Double-click the Catalog.ad file to open the application diagram.
Application Designer displays the application diagram.
Right-click the CatalogWebService endpoint on Catalog and choose Define Operations to view the Web Service Details window.
In the Web Service Details window, click <add operation> and type GetProductDetails.
Under Type, type ProductDetails.
The operation type that you enter here specifies the operation's return type.
Expand plus sign (+) to the left of GetProductDetails to add parameters to the operation.
Click <add parameter> and type ProductNumber. Under Type, type Integer.
When you begin typing in the Type column, Visual Studio displays a list of available types.
This operation takes an integer product number and returns a ProductDetails structure.
The defined operation is request-response by default. For more information about how to change this property, see How to: Specify One-Way or Request-Response Operations for ASP.NET Web Services.
To set project properties and implement the Catalog Web service
Click the CatalogWebService endpoint on the Catalog application.
View the Properties window.
Change the WSDL Binding Name property to Catalog.
Change the WSDL Binding Namespace property to http://Adventureworks/Products.
Click the Catalog application and change its Language property to Visual C#.
If you installed all languages with Visual Studio, the value of this property defaults to Visual Basic.
With the Catalog application selected, on the Diagram menu, point to Implementation, and click Implement Application.
The Confirm Application Implementation dialog box appears.
Review the implementation details for the Catalog application and click OK.
The implementation process generates a project for the application with the appropriate Web references. Once implementation is complete, the application displays with a drop shadow.
When the Security Warning dialog box appears, click Close. This dialog box indicates that the database connection string for the database on the application diagram is being written to the configuration file unencrypted and in plain text.
Review the proxy classes and Web reference in Solution Explorer.
Open the CatalogWebService.cs file and view the code for the ProductDetails Web method.
Notice that Visual Studio has set the WSDL binding name and WSDL binding namespace and has created the method signature.
In code, change the operation name from GetProductDetails to GetProductInformation.
Click the CatalogWebService endpoint and view the Web Service Details window.
The operation name has changed in the Web Service Details window to reflect the change made to the Web method signature in code. Any changes made in code are automatically reflected in the Web Service Details window and vice versa.
To add an external Web service and view Web methods
Open the Toolbox and drag an ExternalWebService to the application diagram.
The Add Web Reference dialog box appears.
Find the location of LegacyCatalog.wsdl on your local machine.
In the URL box, type this location, and click Go.
The description of the WSDL file appears along with the method it defines.
Click Add Reference.
The external Web service appears on the application diagram.
Click the GetLegacyInfo endpoint.
On the View menu, point to Other Windows, and then click Web Service Details to view the Web Service Details window.
Examine the Web method in the Web Service Details window.
This particular WSDL file contains methods for accessing information in a legacy catalog.
To connect the external Web service with the Catalog Web service
While holding the ALT key, drag the GetLegacyInfo endpoint on the external Web service to the border of the Catalog application.
This action creates a consumer endpoint on Catalog, indicating that the Catalog application consumes services provided by LegacyInfo. When you implement the Catalog application, Visual Studio will generate proxy classes for the Web methods defined on the GetLegacyInfo endpoint.
Visual Studio also adds an .sdm file for the external Web service to the solution. This file contains SDM definitions for this application. For more information, see Overview of the System Definition Model (SDM).
The next step is to work more with Web service endpoints. For more information, see Walkthrough: Contract Driven Web Service Design - Creating an Endpoint.