Any server that runs as a program (EXE) will work across a network. In general, you don't have to make any changes to a server to get it towork for DCOM. You may, however, want to add some security to your server, which will involve some effort. I've ignored security in this tutorial to keep things simple, If you're using an in-process server, you will need to make some changes. An in-process server is a DLL, which can't load across a network. A DLL loads into the client program's address space, which will not work for remote connections. There is a work-around called a surrogate,
which wraps the DLL in an executable program; however, it is usually more appropriate to change the server over to an EXE. Generally, the easiest way to convert a DLL to an EXE is to recreate the server using the ATL Wizard and transfer the code from the DLL to the EXE.
For our example I have provided the source code for RemoteServer.exe, which implements a simple EXE-based DCOM server. If you look at the code you will see it is out-of-the-box, wizard-generated code. However, I have added two methods - one to get the server name and another to get the server's system time. After compiling the example, we'll simply copy the client EXE to the client computer. Note that you will also need a proxy/stub DLL because this is a custom interface. You will need to register the proxy/stub DLL on both the client and the server computers. If you are using an automation server with a type library, you will need to copy the typelib and register it on the client computer.
Up a Remote Server Using OLEVIEW and DCOMCNFG
Actually, you can make a server program run remotely just by changing registry settings. There are two Microsoft tools to do this: OLEVIEW and DCOMCNFG. Both tools set the registry so that DCOM tries to find the server on a remote computer. You can type in the remote computer name under the Activation tab of OLEVIEW, and it will be started on that computer. But this is a rather inelegant and inflexible solution, although it does work with older non-DCOM applications. I'm going to concentrate onsetting up the remote activation using programmatic changes to the client. This approach will prove to be more flexible, once you get the hang of it.
0 comments:
Post a Comment