Remoting 如何注册多个类型? 假设以下情景(Remoting):有3个IChannel(8001,8002,8003)那么我现在要在:端口8001和8002 注册远程类型 Type1在8003 注册类型 Type2请问要如何实现? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 RemotingConfiguration.RegisterWellKnownServiceType(typeof(Class.IO), "Class", WellKnownObjectMode.SingleCall);这样不能注册多个么? 没办法用WCF。要求 2.0 除非做成 WEB服务。可是这不是所愿。 你不是已经指定了么?TcpServerChannel channel = new TcpServerChannel(端口); 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; 受鄙视了……囧。这样?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); 在配置文件里配啊,有几个配几个。例子:<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> 你这样是不是:20002端口可以访问 XXXSVC.AAAService和 XXXSVC.BBBService? 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 端口上使用。 能做是能做,比如直接Marshal也可以实现。编码应该可以做到,我想想配置怎么搞 先贴代码控制的: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); 那应该用 WCF 了,找了下没找到解决办法。http://stackoverflow.com/questions/234067/how-to-bind-services-to-specific-channels-tcp-http-ipc-in-a-net-remoting-s 上一个项目就用WCF。已经完美实现效果。但是这次强制要求2.0。我在想想办法吧。谢谢你。 利用 AppDomain !? spreadsheet控件中LanguageSettings属性的用法 有谁了解软路由开发及C#在软路由开发中的应用? 请教下这样的写法吗! 请人解释几行代码,好象和数学有关 ++++++++++举个例子给50分,如何用'回车键'替代这个“按钮”事件???+++++++++++ 工资管理系统 请教上传地址验证的正则表达式写法。在线等,马上揭贴 新手上路!简单控件问题!在线等待! 广交.NET高手以方便讨论高级问题,4个角以上的进来登记 请教,关于Activator.GetObject的问题? C#代理与事件 DriveInfo問題
这样不能注册多个么?
没办法用WCF。要求 2.0
TcpServerChannel channel = new TcpServerChannel(端口);
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;
这样?
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);
<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>
你这样是不是:
20002端口可以访问 XXXSVC.AAAService和 XXXSVC.BBBService?
{
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 端口上使用。
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);
上一个项目就用WCF。已经完美实现效果。但是这次强制要求2.0。
我在想想办法吧。
谢谢你。
利用 AppDomain !?