假设以下情景(Remoting):有3个IChannel(8001,8002,8003)那么我现在要在:
端口8001和8002 注册远程类型 Type1
在8003 注册类型 Type2
请问要如何实现?

解决方案 »

  1.   

    RemotingConfiguration.RegisterWellKnownServiceType(typeof(Class.IO), "Class", WellKnownObjectMode.SingleCall);
    这样不能注册多个么?
      

  2.   


    没办法用WCF。要求 2.0
      

  3.   

    除非做成 WEB服务。可是这不是所愿。
      

  4.   

    你不是已经指定了么?
    TcpServerChannel channel = new TcpServerChannel(端口);
      

  5.   


    BinaryServerFormatterSinkProvider provider = new BinaryServerFormatterSinkProvider();
                provider.TypeFilterLevel = System.Runtime.Serialization.Formatters.TypeFilterLevel.Full;
                BinaryClientFormatterSinkProvider clientProvider = new BinaryClientFormatterSinkProvider();
                IDictionary props = new Hashtable();
                props["port"] = 9999;
                props["name"] = "Class1";
                TcpChannel channel = new TcpChannel(props,clientProvider,provider);
                ChannelServices.RegisterChannel(channel, false);
                RemotingConfiguration.RegisterWellKnownServiceType(typeof(自定义类), "Class1", WellKnownObjectMode.SingleCall);
                RemotingConfiguration.CustomErrorsMode = CustomErrorsModes.Off;
      

  6.   

    受鄙视了……囧。
    这样?
    ChannelServices.RegisterChannel(channel8001, false);
    RemotingConfiguration.RegisterWellKnownServiceType(typeof(Type1), "Type1", WellKnownObjectMode.SingleCall);
    ChannelServices.RegisterChannel(channel8002, false);
    RemotingConfiguration.RegisterWellKnownServiceType(typeof(Type2), "Type2", WellKnownObjectMode.SingleCall);ChannelServices.RegisterChannel(channel8001, false);
    RemotingConfiguration.RegisterWellKnownServiceType(typeof(Type3), "Type3", WellKnownObjectMode.SingleCall);
      

  7.   

    在配置文件里配啊,有几个配几个。例子:<system.runtime.remoting>
      <application>
        <service>
          <wellknown
            type="XXXSVC.AAAService, XXXSVC" objectUri="AAAServices" mode="SingleCall" />
          <wellknown
            type="XXXSVC.BBBService, XXXSVC" objectUri="BBBService" mode="SingleCall" />
        </service>
        <channels>
          <channel ref="tcp" port="20002">
            <serverProviders>
               <formatter ref="binary" typeFilterLevel="Full" />
            </serverProviders>
          </channel>
        </channels>
      </application>
    </system.runtime.remoting>
      

  8.   


    你这样是不是:
    20002端口可以访问 XXXSVC.AAAService和 XXXSVC.BBBService?
      

  9.   

           TestClass<IDemoClass1>("tcp://localhost:8123/Demo1", c =>
                    {
                        this.ShowInfo(c.Add(1, 1).ToString());
                    });
                TestClass<IDemoClass1>("tcp://localhost:8124/Demo2", c =>
                {
                    this.ShowInfo(c.Add(1, 2).ToString());
                });
                TestClass<IDemoClass2>("tcp://localhost:8125/Demo3", c =>
                {
                    this.ShowInfo(c.Subtract(1, 3).ToString());
                });
                TestClass<IDemoClass2>("tcp://localhost:8123/Demo3", c =>
                {
                    this.ShowInfo(c.Subtract(1, 5).ToString());
                });这段连接代码是完全连接成功的。
    但是在 IDemoClass2 我只希望在 8125 端口上使用。
      

  10.   

    能做是能做,比如直接Marshal也可以实现。编码应该可以做到,我想想配置怎么搞
      

  11.   

    先贴代码控制的:BinaryClientFormatterSinkProvider cbin = new BinaryClientFormatterSinkProvider();
    BinaryServerFormatterSinkProvider sbin = new BinaryServerFormatterSinkProvider();
    sbin.TypeFilterLevel = TypeFilterLevel.Full;Hashtable properties1 = new Hashtable();
    properties1["name"] = "channel1";
    properties1["port"] = 8001;
    TcpChannel channel1 = new TcpChannel(properties1, cbin, sbin);
    ChannelServices.RegisterChannel(channel1, false);
    RemotingConfiguration.RegisterWellKnownServiceType(typeof(AService), "AService", WellKnownObjectMode.SingleCall);Hashtable properties2 = new Hashtable();
    properties2["name"] = "channel2";
    properties2["port"] = 8002;
    TcpChannel channel2 = new TcpChannel(properties2, cbin, sbin);
    ChannelServices.RegisterChannel(channel2, false);
    RemotingConfiguration.RegisterWellKnownServiceType(typeof(BService), "BService", WellKnownObjectMode.SingleCall);
      

  12.   

    那应该用 WCF 了,找了下没找到解决办法。http://stackoverflow.com/questions/234067/how-to-bind-services-to-specific-channels-tcp-http-ipc-in-a-net-remoting-s
      

  13.   


    上一个项目就用WCF。已经完美实现效果。但是这次强制要求2.0。
    我在想想办法吧。
    谢谢你。
      

  14.   


    利用 AppDomain !?