服务器端代码:
 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

解决方案 »

  1.   

    If I understand you correctly, you want to seeINFO: Exposing ServicedComponents As a Remoting Endpoint from a COM+ Dllhost.exe Process Is Not Supported
    http://support.microsoft.com/default.aspx?scid=kb;en-us;322627also see
    http://www.gotdotnet.com/team/xmlentsvcs/esfaq.aspx#2.1
      

  2.   

    顶啊>> 但如果把 ServerObject 注册为Com+类,如下面代码,就会出错,这是为什么呢?
    出错信息是什么?哥们,详明点啊。
      

  3.   

    不好意思啊,问题说的不够清楚,我再说详细些:ServerObject 现在是继存自 :MarshalByRefObject,IServerObject(这样运行正确)
    但如果把 ServerObject 改为继存自  :ServicedComponent,IDAL.IDBDAL
    就出错,出错信息是:
    {"无法加载类型 Com_DataAccess.DataOper, Com_DataAccess, Version=1.0.0.0, Culture=neutral, PublicKeyToken=090dc96242cb7f34。" }
      

  4.   

    你给类设置强名称了吗?就是用sn.exe那个工具
      

  5.   

    你的对象要从ServicedComponent继承下来。
      

  6.   

    回复woxihuanbohe(我喜欢): 设置了强名
    回复 songhtao(三十年孤独) :现在的问题是改为继承 ServicedComponent就出错。
      

  7.   

    from the KB article:you want to expose your ServicedComponents by remoting, you can do either of the following: • You can host your ServicedComponents in IIS by selecting uses SOAP on the Activation tab of the properties for the COM+ application. • You can use a custom host that hosts the ServicedComponents from a COM+ library application. 
      

  8.   

    saucer(思归) :明白的意思,我的客户端是c/s结构的,所以我还是先试试 c/s结构的服务器监听程序,实在不行,再使用 iis服务器