zoukankan      html  css  js  c++  java
  • 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服务中可以收到消息了。

      

  • 相关阅读:
    USDT与omniCore钱包
    C# 事件(第四章)
    委托进阶(第三章)
    委托入门(第二章)
    委托入门(第一章)
    asp.net页面生命周期
    在WEB程序中小心使用"ThreadStatic"
    如何在一个请求中共享数据或对象实例
    .net垃圾回收机制原理
    MVC模式简介
  • 原文地址:https://www.cnblogs.com/gisser/p/2308989.html
Copyright © 2011-2022 走看看