- Designing COM+ Applications with a Web Service Appeal
- Creating the COM+ Application
- Defining the Web Service
- Using the Web Service from .NET
Using the Web Service from .NET
The Web service created by COM+ is accessible from any outside source that has the proper permissions. In this section, I show a .NET application accessing the Web service, but you can use anything from PHP to Java to access it as well. The application is a simple Windows Application project.
To access the Web service, you need to create a Web reference. Right click the References folder in Solution Explorer and select Add Web Reference from the context menu. You'll see an Add Web Reference dialog box. Type the WSDL URL for the Web service in the URL field and click Go. The Add Web Reference dialog box should access the Web service and display information about it similar to that shown in Figure 6.
Click Add Reference to add the Web service to your application. Now you can add buttons and code to test it.
Figure
6: The final confirmation that the COM+ application is accessible is the
information the Web service displays.
Listing 2 shows the code I used for testing purposes.
Listing 2: Using the COM+ Application as a Web Service
private void btnAdd_Click(object sender, System.EventArgs e) { // Create a connection to the Web service. SimpleMathService SMS; SMS = new SimpleMathService(); // Perform the addition. txtOutput.Text = SMS.DoAdd(Int32.Parse(txtInput1.Text), Int32.Parse(txtInput2.Text)).ToString(); }
All you need to do is create an object based on the Web services class, SimpleMathService
. This class includes all of the functionality required to interact with the Web service, including any custom methods such as DoAdd()
.
The next step is to use one of the methods to update the current application. In this case, the application retrieves two text values from the form, converts them to Int32 values, and passes them to the DoAdd() method. The DoAdd() method adds the values together and passes them back as an Int32 value, which the code converts to the string and displays on the form.
Bottom Line
The perception that you can't create a compatible application with .NET for just about any need is simply incorrect. This example shows that you can make it compatible with COM and COM+ with ease. In addition, it demonstrates that you don't have to go outside the box to make your investment pay off as a Web service either. Using the correct techniques, you can build extremely flexible components that work with your current infrastructure.