Even though the .NET platform provides a bidirectional interoperability mechanism ” invoking .NET components in COM and invoking COM components in .NET ”Web services provide an alternative way of integrating two technologies. Whereas platform-level interoperability mechanisms typically are sufficient and efficient, Web services always provide a standards-based approach for interoperability. The idea is that COM objects can be exposed as Web services using the Microsoft SOAP Toolkit available from http://www.microsoft.com/soaptoolkit. Next, these Web services can be referenced with applications and services developed using .NET. Similarly, the SOAP Toolkit provides a mechanism for COM-based applications to interact with other Web services, which, in this case, can be a .NET Web service (see Figure 11.9). Figure 11.9. Using SOAP Toolkit 3.0 to generate a Web service for a COM object.
After the Web service is created for the COM object, the WSDL.EXE utility (included in the .NET Framework SDK) can be used to create a Web service proxy class. wsdl http://localhost/soap/TradeAppService.wsdl Following is what the generated code for the Web service proxy looks like: using System.Diagnostics; ... public class TradeAppService : System.Web.Services.Protocols.SoapHttpClientProtocol { ... public TradeAppService() { this.Url = "http://localhost/soap/TradeAppService.WSDL"; } ... public short ExecTrade(string equity, string buyer, string price) { object[] results = this.Invoke("ExecTrade", new object[] { equity, buyer, price}); return ((short)(results[0])); } ... } The generated Web service stub can then be utilized within the .NET Framework like any other Web service. using System; class UseTradeApp { public static void Main() { TradeAppService service = new TradeAppService(); int result = service.ExecTrade("MSFT","hitesh.seth","50"); Console.WriteLine(result); } } csc UseTradeApp.cs TradeAppService.cs
A key benefit to the Web services approach is that it can be applied to interoperate .NET components and applications not only with COM objects, but also with application components developed in other programming languages and frameworks, including Java, J2EE, and Perl (see Figure 11.10). Most of these technologies provide a Web services toolkit, which can be used to expose applications and components developed using that technology as Web services. Figure 11.10. Using Web services for interoperability.
For instance, for interoperability with J2EE technologies, the Java Web Services Developer Pack (java.sun.com/ webservices ) can be used to expose Enterprise Java Beans and other Java objects as Web services. A key to using Web services for an interoperability mechanism is whether the Web services toolkit conforms to the WS-I (Web Services Interoperability) standards organization's framework. |