Share via


Walkthrough: Representing Indirect Web Service Connections 

ASP.NET Web services can be used as facades for business functions written in class libraries. The Distributed System Designers do not support designing or representing class libraries on an application diagram, but the interaction between behavior implemented in class libraries that are referenced by an ASP.NET application and other applications depicted on the application diagram can be represented by Application Designer if the correct configuration file entries are created in the ASP.NET application. The following procedure illustrates how to do this. This procedure can only be completed after code generation (implementation) of the ASP.NET application.

To represent a Class Library project on an application diagram

  1. Open an application diagram.

  2. Add an ASP.NETWebService application to the diagram and name it MyWebService. Select the Web service endpoint label and name the endpoint FirstWebService.

  3. Implement MyWebService.

    This creates the Web service you are going to connect to from a class library, which you will build in a moment.

  4. Add an ASP.NETWebApplication to the diagram, MyWebApplication and implement it. This creates the client Web application that will use functions in the class library to access the Web service built above.

  5. Select the ASP.NETWebApplication, right-click, and choose Settings and Constraints to view the Settings and Constraints Editor.

  6. Under Application Settings, WebApplication, Configuration, select NetSectionGroup, right-click, choose Add Resource and then choose SettingsSection.

    After adding this resource, web.config displays in Solution Explorer.

    Note

    The web.config file is not available in Solution Explorer until the Web application is implemented (that is, project and code files are generated) and one of the default web.config settings is modified directly in the Settings and Constraints Editor or indirectly through another action on the application diagram. Examples of indirect actions that modify web.config include connecting the Web application to an external Web service or an external database.

  7. In Solution Explorer, right-click the Solution node and choose Add New Project.

    The Add New Project dialog box appears.

  8. Under Project types, choose Visual Basic or Visual C#, Windows. Under Templates, choose Class Library and click OK.

  9. Select the class library project in Solution Explorer, right-click and choose Add Web Reference.

    The Add Web Reference dialog box appears.

  10. Click Web services in this solution.

  11. Under Web Services in this Solution, click the MyWebService Web service you added and then click Add Reference.

    This creates in the class library, a Web reference to the Web service you created.

  12. Build the class library.

    This creates an app.config file in the class library project.

  13. Select the MyWebApplication Web application project, right-click, and choose Add Reference.

    The Add Reference dialog box appears.

  14. Select the Projects tab in the dialog box and then select the class library project. Click OK.

  15. Open the web.config file in the Web application project.

  16. Open the app.config file from the class library project.

  17. Copy the applicationSettings section group from app.config and paste it into web.config. Make sure you also copy in the configSections element. The section group looks similar to this:

    <configSections>
    <sectionGroup name="applicationSettings" type="System.Configuration.ApplicationSettingsGroup, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" >
                <section name="ClassLibrary1.Settings" type="System.Configuration.ClientSettingsSection, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
            </sectionGroup>
    </configSections>
    
  18. Copy the applicationSettings section from app.config and paste it into web.config below configSections. The applicationSettings section will look something like this:

    <applicationSettings>
        <ClassLibrary1.Settings>
            <setting name="ClassLibrary1_localhost_WebService1" serializeAs="String">
    <value>https://localhost:1665/MyWebService/FirstWebService.asmx</value>
            </setting>
        </ClassLibrary1.Settings>
    </applicationSettings>
    

    The beginning of web.config should now look like this:

    <configuration xmlns="https://schemas.microsoft.com/.NetConfiguration/v2.0">
        <configSections>
            <sectionGroup name="applicationSettings" type="System.Configuration.ApplicationSettingsGroup, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" >
                <section name="ClassLibrary1.Settings" type="System.Configuration.ClientSettingsSection, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
            </sectionGroup>
        </configSections>
        <appSettings>
        </appSettings>
        <applicationSettings>
            <ClassLibrary1.Settings>
                <setting name="ClassLibrary1_localhost_WebService1" serializeAs="String">
                    <value>https://localhost:1665/MyWebService/FirstWebService.asmx</value>
                </setting>
            </ClassLibrary1.Settings>
        </applicationSettings>
        <connectionStrings/>
        <system.web>
    
  19. Build the solution and then view the application diagram.

  20. A consumer endpoint appears on the MyWebApplication Web application connected to the FirstWebService Web service endpoint on MyWebService. This endpoint represents the connection from the Web reference in the class library project to the Web service.

See Also

Other Resources

Designing Web Services Walkthroughs
Referencing Class Libraries from Applications on Application Diagrams