Using COM Applications in .NET

Team Fly 

Page 465

This is how you can use a COM component in your .NET applications, regardless of whether it's a legacy component you developed with VB6 or a third-party control. The source code is not required and you don't have to create the interoperability layer yourself; instead, the IDE will create it as needed and will also copy it to the project's output directory. This means that interop assemblies will be distributed with the project's setup application.

TIP The CLR can determine the dependencies of your code on COM components and include them automatically in the project's output when you build the application's setup program (the MSI package, as discussed in Chapter 10). However, it can't determine the dependencies of the COM component. If the COM component has dependencies of its own, you must add them to the project's output manually.

Using COM+ Applications in .NET

In many situations, middle-tier components are distributed to the production environment as COM+ applications. A COM+ application runs as a Component Service: that is, the component is hosted by the Component Services on an application server and any number of client machines can contact the server and request an instance of the component. There are many benefits to this approach, especially for large-scale applications. COM+ applications can be used to create objects that run on the application server, not on the client. They can participate in transactions and, most importantly, you can maintain a pool of objects on the server to service a large number of clients.

Let's start by reviewing the process of creating a COM+ application with VB6. First, you create a class as usual. The class's compiled code, which is a DLL, can be installed on an application server as a COM+ application. This is done with the help of the Component Services Explorer (or the Component Services console). You simply create a new COM+ application and add the new component (the DLL) to the application. The COM+ application can be configured easily from within the Component Services Explorer. You can specify whether the component will run at the server or the client, whether the component will participate in transactions, and whether the component can be pooled. You can also determine who can access the component. All these operations take place through a point-and-click interface, and you don't have to modify the DLL's code or the application that uses it.

Once the COM+ application has been installed and configured, you create a proxy for the clients. The Component Services Explorer will export the application into an MSI package, which you distribute and install at the clients. The MSI package will install a proxy for the actual COM+ component at the client. The proxy appears at the client as a new COM+ application and any application on the client can contact it. However, you can't set the component's properties through the proxy.

What does it take to use an existing COM+ application in a .NET client application? Basically, once the proxy has been installed on the client machine, you can add a reference to the COM+ proxy as we demonstrated in the preceding section. The IDE will create an interop assembly, which will be included in the .NET project. Let's look at the process by building a simple application. For the example of the following section we'll assume that you have VB6 installed on your system, which you'll use to create a COM component. If not, you can copy the sample DLL that's included in the zip file with this chapter's projects.

Team Fly 


Visual Basic  .NET Power Tools
Visual Basic .NET Power Tools
ISBN: 0782142427
EAN: 2147483647
Year: 2003
Pages: 178

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net