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

  1. Load the sample provided at https://go.microsoft.com/fwlink/?LinkId=40867.

  2. Double-click the Catalog.ad file to open the application diagram.

    Application Designer displays the application diagram.

  3. Right-click the CatalogWebService endpoint on Catalog and choose Define Operations to view the Web Service Details window.

  4. In the Web Service Details window, click <add operation> and type GetProductDetails.

  5. Under Type, type ProductDetails.

    The operation type that you enter here specifies the operation's return type.

  6. Expand plus sign () to the left of GetProductDetails to add parameters to the operation.

  7. Click <add parameter> and type ProductNumber. Under Type, type Integer.

    Note

    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

  1. Click the CatalogWebService endpoint on the Catalog application.

  2. View the Properties window.

  3. Change the WSDL Binding Name property to Catalog.

  4. Change the WSDL Binding Namespace property to http://Adventureworks/Products.

  5. Click the Catalog application and change its Language property to Visual C#.

    Note

    If you installed all languages with Visual Studio, the value of this property defaults to Visual Basic.

  6. With the Catalog application selected, on the Diagram menu, point to Implementation, and click Implement Application.

    The Confirm Application Implementation dialog box appears.

  7. 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.

    Note

    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.

  8. Review the proxy classes and Web reference in Solution Explorer.

  9. 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.

  10. In code, change the operation name from GetProductDetails to GetProductInformation.

  11. 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

  1. Open the Toolbox and drag an ExternalWebService to the application diagram.

    The Add Web Reference dialog box appears.

  2. Find the location of LegacyCatalog.wsdl on your local machine.

  3. In the URL box, type this location, and click Go.

    The description of the WSDL file appears along with the method it defines.

  4. Click Add Reference.

    The external Web service appears on the application diagram.

  5. Click the GetLegacyInfo endpoint.

  6. On the View menu, point to Other Windows, and then click Web Service Details to view the Web Service Details window.

  7. 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).

Next Steps

The next step is to work more with Web service endpoints. For more information, see Walkthrough: Contract Driven Web Service Design - Creating an Endpoint.

See Also

Other Resources

Designing Web Services Walkthroughs