服务器端代码:
public interface IServerObject
{
Person GetPersonInfo(string name,string sex,int age);
} public interface IServerObjFactory
{
IServerObject CreateInstance();
} public class ServerObject:MarshalByRefObject,IServerObject
{
public Person GetPersonInfo(string name,string sex,int age)
{
Person person = new Person();
person.Name = name;
person.Sex = sex;
person.Age = age;
return person;
}
} public class ServerObjFactory:MarshalByRefObject,IServerObjFactory
{
public IServerObject CreateInstance()
{
return new ServerObject();
}
}
//传递对象;
RemotingConfiguration.RegisterWellKnownServiceType(
typeof(ServerRemoteObject.ServerObjFactory),
"ServiceMessage",WellKnownObjectMode.SingleCall);
客户端代码:
ServerRemoteObject.IServerObjFactory serverFactory =
(ServerRemoteObject.IServerObjFactory) Activator.GetObject(
typeof(ServerRemoteObject.IServerObjFactory),
"tcp://localhost:8080/ServiceMessage");ServerRemoteObject.IServerObject serverObj = serverFactory.CreateInstance();这样执行没问题,
但如果把 ServerObject 注册为Com+类,如下面代码,就会出错,这是为什么呢?
public class ServerObject:ServicedComponent,IServerObject
public interface IServerObject
{
Person GetPersonInfo(string name,string sex,int age);
} public interface IServerObjFactory
{
IServerObject CreateInstance();
} public class ServerObject:MarshalByRefObject,IServerObject
{
public Person GetPersonInfo(string name,string sex,int age)
{
Person person = new Person();
person.Name = name;
person.Sex = sex;
person.Age = age;
return person;
}
} public class ServerObjFactory:MarshalByRefObject,IServerObjFactory
{
public IServerObject CreateInstance()
{
return new ServerObject();
}
}
//传递对象;
RemotingConfiguration.RegisterWellKnownServiceType(
typeof(ServerRemoteObject.ServerObjFactory),
"ServiceMessage",WellKnownObjectMode.SingleCall);
客户端代码:
ServerRemoteObject.IServerObjFactory serverFactory =
(ServerRemoteObject.IServerObjFactory) Activator.GetObject(
typeof(ServerRemoteObject.IServerObjFactory),
"tcp://localhost:8080/ServiceMessage");ServerRemoteObject.IServerObject serverObj = serverFactory.CreateInstance();这样执行没问题,
但如果把 ServerObject 注册为Com+类,如下面代码,就会出错,这是为什么呢?
public class ServerObject:ServicedComponent,IServerObject
http://support.microsoft.com/default.aspx?scid=kb;en-us;322627also see
http://www.gotdotnet.com/team/xmlentsvcs/esfaq.aspx#2.1
出错信息是什么?哥们,详明点啊。
但如果把 ServerObject 改为继存自 :ServicedComponent,IDAL.IDBDAL
就出错,出错信息是:
{"无法加载类型 Com_DataAccess.DataOper, Com_DataAccess, Version=1.0.0.0, Culture=neutral, PublicKeyToken=090dc96242cb7f34。" }
回复 songhtao(三十年孤独) :现在的问题是改为继承 ServicedComponent就出错。