1. 准备工作:两台主机,各自软件配置分别为
1. 服务器:Vs.net 2003 + .Net Framework 1.1 SDK SP1 + WinXP pro SP2
1. 客户端:.Net Framework 1.1 SP1 Distributed Package + WinXP pro SP2
2. 在服务器上新建一个C# Class Library工程,将System.EnterpriseServices.dll添加进项目引用
3. 开启Vs.net 2003命令提示控制台,在%Project Directory%目录下生成一个用于组件签名的密钥对,输入
3. sn -k keyfile.snk
4. 修改项目的AssemblyInfo.cs文件,在其中添加引用声明:
using
System.EnterpriseServices;
[assembly: AssemblyDelaySign(
false
)]
[assembly: AssemblyKeyFile( " ..\\..\\keyfile.snk " )]
[assembly: AssemblyKeyName( "" )]
[assembly: ApplicationActivation(ActivationOption.Server)]
[assembly: ApplicationAccessControl( false )]
[assembly: AssemblyKeyFile( " ..\\..\\keyfile.snk " )]
[assembly: AssemblyKeyName( "" )]
[assembly: ApplicationActivation(ActivationOption.Server)]
[assembly: ApplicationAccessControl( false )]
5. 修改项目Class1.cs文件,添加COM+服务器组件的主体内容如下:
using
System;
using System.EnterpriseServices;
namespace ccc
{
public interface IMathEx
{
int sum(int a,int b);
}
public class Test: ServicedComponent,IMathEx
{
public Test()
{
}
IMathEx 成员#region IMathEx 成员
public int sum(int a,int b)
{
return a+b;
}
#endregion
}
}
using System.EnterpriseServices;
namespace ccc
{
public interface IMathEx
{
int sum(int a,int b);
}
public class Test: ServicedComponent,IMathEx
{
public Test()
{
}
IMathEx 成员#region IMathEx 成员
public int sum(int a,int b)
{
return a+b;
}
#endregion
}
}
6. 编译工程项目,%Project Directory%\bin\debug目录下将生成ccc.dll和ccc.tlb两个文件
7. 在%Project Directory%\bin\debug目录下手工注册Assembly至COM+目录,键入命令:
7. regsvcs -appname:MyApp ccc.dll
8. 至此服务器端组件开发、部署完毕