C#中Remoting的IPC通信之Winform与Windows服务通信错误问题及解决

按照传统的写法我试过好多次都发现通过Winform向Windows服务发送消息Windows服务收不到,而在两个Winform程序之间却可以正常通信。代码如下:

IpcServerChannel serverChannel = new IpcServerChannel("ipc");
ChannelServices.RegisterChannel(serverChannel, false); RemotingConfiguration.RegisterWellKnownServiceType(typeof(RemotingObject), "hi", WellKnownObjectMode.SingleCall);

后来在查找解决此问题的方法时看到别人写过的代码:

           IpcServer Channel BinaryServerFormatterSinkProvider provider = new BinaryServerFormatterSinkProvider();
provider.TypeFilterLevel = TypeFilterLevel.Full;
Hashtable ht = new Hashtable();
ht["portName"] = "ServerChannel";
ht["name"] = "ipc";
ht["authorizedGroup"] = "Everyone";
serverChannel = new IpcServerChannel(ht, provider);
ChannelServices.RegisterChannel(serverChannel, false); RemotingConfiguration.RegisterWellKnownServiceType(typeof(RemotingObject), "hi", WellKnownObjectMode.Singleton);

这样试了一下,在Windows服务中可以收到消息了。

  

posted on 2011-12-31 17:31  Hexy  阅读(1372)  评论(0编辑  收藏  举报

导航