Interop with SOAP

SOAP stands for Simple Object Access Protocol. SOAP is a protocol and a standard for interoperating using XML. Currently, the primary transport that is used for SOAP communications is HTTP, although the specification does not demand that HTTP be used. When combined with a Web server such as IIS, SOAP forms the basis for Web services. With COM+ 1.5 (which is only available on Windows XP platforms and Windows.NET servers), it is possible to interop with a COM+ component through a Web service. Figure 8.10 shows a block diagram of how the interaction is possible with COM+ 1.5.

Figure 8.10. Interoperating with SOAP.


If you are unfamiliar with how to place a COM object under the control of the COM+ services, read on for a step-by-step overview. For more detail on COM+ services, refer to Transactional COM+: Building Scalable Applications by Tim Ewald (ISBN 0-201-61594-0, Addison-Wesley) or COM and .NET Component Services by Juval Lowy (ISBN 0-596-00103-7, O'Reilly).

  • First, click Control Panel, Administrative Tools, Component Services.

  • Second, drill down into My Computer in the Component Services portion of the tree until you reach the COM+ Applications node.

  • Third, select the COM+ Applications node. Then right-click to select the menu item New, Application. The wizard guides you through creating a new COM+ application. In the wizard, select Create an Empty Application and give it any name that is appropriate. The Arithmetic COM component has been named Arithmetic.

  • Fourth, select the application you have just created. On the right pane, right-click on the Components folder and select New, Component. Again, a wizard guides you through adding a new component to your application. Select Install New Component(s), which brings up a File dialog box that you can use to point to your DLL that implements your COM object. If you are going through these steps to install the Arithmetic COM object, look for the Arithmetic DLL. After you have selected your DLL, a dialog box appears where you can add more components. Just click on the Next button and Finish to complete this session with the wizard.

  • Fifth, you should see your component in the Components folder. Go back to select your application and right-click to select the Properties menu. This brings up a dialog box with many property pages. Select the Activation tab.

  • Sixth, in the SOAP group box is a Uses SOAP check box. Check the Uses SOAP check box and fill in the name for the IIS virtual directory in the SOAP VRoot text box. This is the virtual IIS directory by which you can access your component. For example, you need to go through these steps for the Arithmetic component and a reasonable name for this application would be Arithmetic. With this name, you can access your component through SOAP with the URL http://localhost/Arithmetic.

  • Seventh, type the URL for your component in Internet Explorer (using localhost as the address portion of the URL). You should see the name of your application as a header followed by a hyperlink to the WSDL description for your COM component. Again, if you were using the Arithmetic component, it would look like this:

    Arithmetic.BinaryOperations.1.soap?WSDL.
    

  • Finally, to access your COM object through .NET, you can use the wsdl tool to generate code for you. From a command prompt, enter something like:

    wsdl http://localhost/Arithmethic/Arithmetic.BinaryOperations.1.soap?WSDL /out:Arithmetic.cs
    

These steps have used the Arithmetic COM object as an example. You need to perform these steps to install the Arithmetic sample that is supplied in the Arithmetic directory. You would naturally change the appropriate arguments to point to your COM object.

After completing these steps, you are ready to build a .NET application that uses these new Web services. I have included a sample application that uses the Arithmetic COM component in the SOAP directory. As part of this project, the code that was generated from the wsdl tool (Arithmetic.cs) has been included. The code that actually calls the methods on this component is shown in Listing 8.8.

Listing 8.8. Calling a COM Component Methods Using SOAP
CBinaryOperationsClassBinding math = new CBinaryOperationsClassBinding();
dd: {0} ", math.Add(1.0F, 2.0F));
Console.WriteLine("Subtract: {0} ", math.Subtract(6.0F, 3.0F));
Console.WriteLine("Multiply: {0} ", math.Multiply(2.0F, 1.5F));
Console.WriteLine("Divide: {0} ", math.Divide(6.0F, 2.0F));

Listing 8.8 shows how you can interop with an existing COM component using SOAP and .NET; with this method, however, any application that understands SOAP can interoperate with your COM component. You do not have to know anything about SOAP to use this technology and you do not need to reprogram your COM component. It just works!

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.219.14.63