Regarding the use of COM in COM is like this: COM requires server-side and clients, personal opinion COM is more suitable in the B / S system.
About server construction is this:
1. First create a category library. (Here we name it Testcom)
It generates two files, assemblyinfo.cs and class1.cs
2, add new classes (Server.cs)
3, add reference (System.EnterpriseServices)
4. Go back to class1.cs to the interface.
Using system;
Namespace Testcom {public interface class1 {string test ();}}
5. Open the code of Server.cs
Add a reference in the code using: use System.EnterpriseServices
Inheriting Server.cs in ServicesDComponent, Class1. It will automatically have a prompt, press Tab. . . . .
The specific code is as follows:
Using System; Using System.EnterpriseServices;
Summary description of Namespace Testcom {///
Public string test () {string a = "mm"; return a; // casually pass a String
}
#ndregion}}}
6. Go back to AssemblyInfo.cs, add the reference using system.enterprisservices;
Add code:
// Set the component to the server startup mode. [assmbly: ApplicationActivation (ActivationOption.server)]
/ / Develop application server name [Assembly: ApplicationName ("Server")]
Next, give the server program a strong name. (Equivalent to registration)
7. Open the Visual Studio .Net2003 command prompt
Find the address of the file, enter SN -K, generate a key
For example, my file is in the E disk, C #,
E: / C # / testcom / testcom> Sn -k server.snk;
Server.snk is the name generated file name (after execution, one file server.snk)
8. After the strong name is generated, return to the program
In the last row in AssemblyInfo.cs, you can find [Assembly: askEMBLYKEYFILE (")]
Write the file path [Assembly: askEMBLYKEYFILE ("../../ Server.snk")]
9, generate a solution, there will be a Testcom.dll in Obj / Debug
Go back to the Visual Studio .NET2003 command prompt, go to the file OBJ / Debug directory, execute the regsvcs command, register service.
I am like this machine.
E: / c # / testcom / testcom / obj / debug> regsvcs testcom.dll; This, the server is built.
Open my computer, control panel, manage tools, component services, COM applications,
Now we can see more than COM , Server
This is the server you built.
10. Press the right click on Server, open the property, modify the security: call the authentication level as: no, analog level is identified. The lichesed check (this is based on the situation, now just do the list on this machine). Then find the activation, the remote server name is changed to your own machine's IP address. 11. Establish a client.
Built a WinFrom
Add reference: Using System.EnterpriseServices
USING TESTCOM;
On the place where the client is referenced, you can use it directly.
This is just a little understanding of COM , if there is any problem, you can contact me, discuss together, QQ: 37942063