How to: Reference Class Libraries from Applications on Application Diagrams
In Application Designer, you can represent references to class libraries from applications on the application diagram. Though Application Designer does not support the design or direct representation of class libraries on the application diagram, you can use an ASP.NET Web service as a façade for functionality implemented by a class library. You can then reverse-engineer references to that class library from other applications as connections from those applications to that Web service.
The following list outlines the steps you need to take to accomplish this task:
Add an ASP.NET Web service to your solution and reference the Web service from the class library.
Reference the class library from the consumer application, which can be an ASP.NET, Windows, or Office application that already exists or that you add to the application diagram.
Copy the appropriate entries from the class library configuration file to the consumer application configuration file.
These steps will reverse-engineer a Web service consumer endpoint on the consumer application and a connection to the ASP.NET Web service.
You can also use this technique to visualize Web references or custom Web service client proxy classes defined in class libraries as Web service consumer endpoints and connections on the application diagram. However, you cannot represent these elements using Application Designer by first designing the Web service consumer endpoints and then adding the appropriate configuration file entries. For more information, see Web References and Custom Web Service Client Proxy Classes in Class Libraries.
To reference a Web service from a class library
Open the application diagram (.ad) file.
Add an ASP.NET Web service to the diagram.
For more information, see How to: Define Applications on Application Diagrams.
This Web service will make it possible for other applications to reference a class library by consuming the Web service.
On the diagram, choose an existing Windows or ASP.NET application as the consumer application or add a new one.
Implement the ASP.NET Web service and the consumer application, if they are not already implemented.
For more information, see How to: Implement Applications on Application Diagrams. The ASP.NET Web service must be implemented before you can add a Web service reference to the class library. The consumer application must be implemented so that you can later edit its configuration file.
The consumer application will use the functionality of the class library to call the Web service.
If needed, add a new or existing class library project to the solution.
An App.config file must exist in the class library project so that the appropriate configuration file entries are added when the Web reference is added.
If the configuration file is missing from the class library, ASP.NET Web service, or consumer application project, add the appropriate configuration file (App.config or Web.config) to the class library project.
To add a configuration file, select the project node in Solution Explorer, choose Add New Item from the Project menu, and choose Application Configuration File or Web Configuration File as appropriate in the Add New Item dialog box.
In Solution Explorer, select the class library project node and choose Add Web Reference from the Project menu.
In the Add Web Reference dialog box, click Web Services in this solution, choose the Web service you created, and click Add Reference.
In Solution Explorer, a Web service reference is added to the Web References folder in the class library project.
In Solution Explorer, select the class library project node and choose Build <ClassLibraryName> from the Build menu.
You can also right-click the project node and choose Build. After adding new Web references, rebuild the class library prior to copying configuration file entries and adding the class library reference. Otherwise, Web service references in Visual Basic class libraries might not reverse-engineer if the class library is built as the last step after copying the configuration file entries and adding the class library reference to the consumer application. For more information, see Troubleshooting Application Diagrams.
You are now ready to add a class library reference to the consumer application.
If the configuration file is missing or deleted from the class library project after you have added the Web references to the project, you can add a new configuration file to the project. However, the Web references will not be automatically added to the configuration file. You will need to remove the Web references from the project and then add them back to the project, which creates a new configuration file containing entries for the added Web references.
To reference the class library from the consumer application
In Solution Explorer, select the consumer application project node and choose one of the following:
For a Windows or Office application, choose Add Reference from the Project menu.
For an ASP.NET application, choose Add Reference from the Website menu.
You can also right-click the root project node and choose Add Reference.
In the Projects tab, select the class library project and click OK.
To copy entries from the class library configuration file to the consumer application configuration file
Open the App.config file in the class library project and the configuration file in the consumer application project.
From the class library App.config file, copy the following entries from the <configSections> and <applicationSettings> sections.
Include the enclosing <configSections> or <applicationSettings> tags if they do not exist in the destination configuration file. If you are copying entries for multiple class libraries, copy only one set of "applicationSettings" <sectionGroup> tags.
<configSections> <sectionGroup name="applicationSettings" type="System.Configuration.ApplicationSettingsGroup, System, Version=VersionNumber, Culture=neutral, PublicKeyToken=b77a5c561934e089"> <section name="ClassLibraryName.Settings" type="System.Configuration.ClientSettingsSection, System, Version=184.108.40.206, Culture=neutral, PublicKeyToken=b77a5c561934e089" /> </sectionGroup> </configSections> <applicationSettings> <ClassLibraryName.Settings> <setting name="ClassLibraryName_WebServiceProxyClassName" serializeAs="String"> <value>http://WebServiceURL.asmx</value> </setting> </ClassLibraryName.Settings> </applicationSettings>
Paste the copied entries into the <configuration> section immediately following the <configuration> tag in the consumer application's configuration file.
In Solution Explorer, select the root solution node and choose Build Solution from the Build menu.
You can also right-click the root solution node and choose Build Solution.
On the application diagram, a Web service consumer endpoint is reverse-engineered on the consumer application and is connected to the ASP.NET Web service.
Web service references might not reverse-engineer correctly in the following scenarios:
Web service references might not reverse-engineer correctly when a Windows and ASP.NET Web project both reference the same class library.
To resolve this condition, close the application diagram and remove the references to the shared class library from the Windows and ASP.NET Web projects. First add the class library reference to the ASP.NET Web project, open the application diagram, and then add the class library reference to the Windows project. For more information, see Troubleshooting Application Diagrams.
Web service references in Visual Basic class libraries might not reverse-engineer correctly when a consumer application references multiple class libraries and each of those libraries contains a Web reference to a different Web service.
To resolve this condition, update all the Web references in the affected class libraries. Right-click each Web reference in each class library affected, choose Update Web Reference, and then rebuild the entire solution. After adding new Web references and rebuilding the corresponding class libraries, rebuild the entire solution again to reverse-engineer these Web references.