none
Remoting 服务端注册多信道问题! RRS feed

  • 问题

  •  最近开发一个项目时使用了Remoting ,最开始的时候服务端是在app.config内配置信息的

    <?xml version="1.0" encoding="utf-8" ?>
    <configuration>
     <appSettings>
      <add key="LotteryConstring" value="server=(local);database=cnhjh;uid=sa;pwd=111111XsdXs"/>
     </appSettings>
     <system.runtime.remoting>
      <application name="CServer">
       <service>
        <wellknown mode="SingleCall" type="Cers.Achieve.User, Cers.Achieve" objectUri="Service" />
       </service>
       <channels>
        <channel ref="tcp" port="4000">
         <serverProviders>
          <formatter ref="soap" typeFilterLevel="Full"/>
          <formatter ref="binary" typeFilterLevel="Full"/>
         </serverProviders>
        </channel>
       </channels>
      </application>
     </system.runtime.remoting>
    </configuration>

    服务端使用4000端口监听, 现在老板提出了一个新的要求,需要开多个端口,于是我这样创建

                IChannel ser1 = new TcpServerChannel("Server1", 4000, new BinaryServerFormatterSinkProvider());
                ChannelServices.RegisterChannel(ser1, false);

                IChannel ser2 = new TcpServerChannel("Server2", 4100, new BinaryServerFormatterSinkProvider());
                ChannelServices.RegisterChannel(ser2, false);

    这样创建两个信道是能够成功的!

    但是这样创建的信道是用默认信息创建的,我需要指定自己的application信息。所以我这样写

                TcpServerChannel tcpChannel = new TcpServerChannel(4000);
                RemotingConfiguration.RegisterWellKnownServiceType(typeof(Achieve),"Service",WellKnownObjectMode.SingleCall);
                ChannelServices.RegisterChannel(tcpChannel, false);

                TcpServerChannel tcpChannel2 = new TcpServerChannel(4100);
               
                RemotingConfiguration.RegisterWellKnownServiceType(typeof(Achieve), "Service1", WellKnownObjectMode.SingleCall);
                ChannelServices.RegisterChannel(tcpChannel2, false);

    这样就实现了相当于config文件内
     <service>
        <wellknown mode="SingleCall" type="Cers.Achieve.User, Cers.Achieve" objectUri="Service" />
       </service>
    项的设定。

    但是这样一来,就出现了TCP信道已注册的错误,在第二个信道注册时。

    简单点说,我想实现在服务端创建多个信道,这个信道的配置信息使用自定义的! 谢谢,刚接触Remoting,还望各位大虾指教!

    2009年8月15日 6:27

答案

  • 为每个 Channel 取一个不同的名字, channels 下是可以配置多个 channel 的
    TcpServerChannel tcpChannel = new TcpServerChannel("tcpChannel", 4000);
    RemotingConfiguration.RegisterWellKnownServiceType(typeof(Achieve), "Service", WellKnownObjectMode.SingleCall);
    ChannelServices.RegisterChannel(tcpChannel, false);
    
    TcpServerChannel tcpChannel2 = new TcpServerChannel("tcpChannel2", 4100);
    RemotingConfiguration.RegisterWellKnownServiceType(typeof(Achieve), "Service1", WellKnownObjectMode.SingleCall);
    ChannelServices.RegisterChannel(tcpChannel2, false);


    知识改变命运,奋斗成就人生!
    2009年8月15日 7:04
    版主

全部回复

  • 为每个 Channel 取一个不同的名字, channels 下是可以配置多个 channel 的
    TcpServerChannel tcpChannel = new TcpServerChannel("tcpChannel", 4000);
    RemotingConfiguration.RegisterWellKnownServiceType(typeof(Achieve), "Service", WellKnownObjectMode.SingleCall);
    ChannelServices.RegisterChannel(tcpChannel, false);
    
    TcpServerChannel tcpChannel2 = new TcpServerChannel("tcpChannel2", 4100);
    RemotingConfiguration.RegisterWellKnownServiceType(typeof(Achieve), "Service1", WellKnownObjectMode.SingleCall);
    ChannelServices.RegisterChannel(tcpChannel2, false);


    知识改变命运,奋斗成就人生!
    2009年8月15日 7:04
    版主
  •  唉,又在问小白问题了,上面创建的时候我都记得加实例名,结果下面就忘记了,搞出这出乌龙,斑竹见笑了,。。

    2009年8月15日 7:22