Windows App中使用App.Config的WCF命名管道 [英] WCF Named Pipe in Windows Service using App.Config

查看:113
本文介绍了Windows App中使用App.Config的WCF命名管道的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我很沮丧.好的,这是错误.

在net.pipe://localhost/MyIpcAppToService上没有侦听终结点的端点可以接受该消息.这通常是由不正确的地址或SOAP操作引起的.有关更多详细信息,请参见InnerException(如果存在).

我终于使App.Config文件正常运行,至少没有任何抱怨.

当前App.Config

 <?xml version ="1.0" encoding ="utf-8"?><配置><!-部署服务库项目时,必须将配置文件的内容添加到主机的app.config文件.System.Configuration不支持库的配置文件.-><启动>< supportedRuntime版本="v4.0" sku =.NETFramework,Version = v4.6.2"/></startup>< system.serviceModel><服务>< service behaviorConfiguration ="MyServiceBehavior" name ="MyService.Communication.IpcAppToService"><端点地址="net.pipe://localhost/MyIpcAppToService" binding ="wsDualHttpBinding" bindingConfiguration ="MyAppToServiceEndpointBinding" contract ="MyIpc.IIpcAppToService"/><端点地址="mex" binding ="mexHttpBinding" name ="mex" contract ="IMetadataExchange"/><主机>< baseAddresses>< add baseAddress ="http://localhost:8733/MyService/"/></baseAddresses></host></service></services><行为>< serviceBehaviors>< behavior name ="MyServiceBehavior"><!-为避免泄露元数据信息,请在部署前将以下值设置为false.< serviceMetadata httpGetEnabled ="true" httpsGetEnabled ="true"/><!-要在故障中接收异常详细信息以进行调试,请将下面的值设置为true.部署前设置为false以避免泄露异常信息->< serviceDebug includeExceptionDetailInFaults ="true"/>< dataContractSerializer maxItemsInObjectGraph ="2147483647"/></行为></serviceBehaviors></行为>< protocolMapping>< add scheme ="http" binding ="wsHttpBinding" bindingConfiguration ="MyAppToServiceEndpointBinding"/></protocolMapping>< bindings>< wsDualHttpBinding><!-https://docs.microsoft.com/zh-cn/dotnet/framework/configure-apps/file-schema/wcf/wshttpbinding->< binding name ="MyAppToServiceEndpointBinding"transactionFlow ="true"sendTimeout ="00:01:00"maxReceivedMessageSize ="2147483647"messageEncoding ="Mtom"></binding></wsDualHttpBinding></bindings>< serviceHostingEnvironment aspNetCompatibilityEnabled ="true" multipleSiteBindingsEnabled ="true">< baseAddressPrefixFilters>< add prefix ="http://localhost:8733"/></baseAddressPrefixFilters></serviceHostingEnvironment></system.serviceModel>< appSettings>< add key ="countoffiles" value ="7"/><添加key ="logfilelocation" value ="abc.txt"/></appSettings></configuration> 

我曾经有过:

 <端点地址="http://localhost:8733/MyIpcAppToService" ... 

并在Windows服务 OnStart()事件中:

(由于此问题帖,下面的代码现在已被注释掉,因为应该将 App.config 文件启动named.pipe.)

 公共布尔型CreatePipeServer(){字符串eventText = $我的服务:CommAppToService :: CreatePipeServer(IPC应用到服务){Environment.NewLine}";尝试{如果(null!= this.ServiceParent.HostIpcAppToService)this.ServiceParent.HostIpcAppToService = null;字符串pipeBaseAddress = @"net.pipe://localhost/MyIpcAppToService";this.ServiceParent.HostIpcAppToService = new ServiceHost(typeof(IpcAppToService),new Uri(pipeBaseAddress));NetNamedPipeBinding pipeBinding =新的NetNamedPipeBinding(){//ReceiveTimeout = new TimeSpan(0,0,0,0,Constants.My_TimeoutMsSendReceive),//SendTimeout = new TimeSpan(0,0,0,0,Constants.My_TimeoutMsSendReceive),};this.ServiceParent.HostIpcAppToService.AddServiceEndpoint(typeof(IIpcAppToService),pipeBinding,"MyIpcAppToService");this.ServiceParent.HostIpcAppToService.UnknownMessageReceived + = HostIpcAppServer_UnknownMessageReceived;this.ServiceParent.HostIpcAppToService.Faulted + = HostIpcAppServer_Faulted;this.ServiceParent.HostIpcAppToService.Closing + = HostIpcAppServer_Closing;this.ServiceParent.HostIpcAppToService.Closed + = HostIpcAppServer_Closed;this.IpcAppToService =新的IpcAppToService();this.IpcAppToService.ApplyDispatchBehavior(this.ServiceParent.HostIpcAppToService);this.IpcAppToService.Validate(this.ServiceParent.HostIpcAppToService);this.ServiceParent.HostIpcAppToService.Open();返回true;} 

我了解到该服务将自动启动放置在 App.Config 文件(实际上是 MyExeName.exe.config 文件)中的服务.我一直在看代码,发现它几乎是相同的,所以我用 net.pipe://替换了 http://.

可悲的是,旧代码,新代码,介于两者之间的代码,什么都没有.我一直收到同样的错误.

我使用以下内容从桌面应用程序连接到服务.

 公共静态布尔值ConnectToService(){尝试{var callback = new IpcCallbackAppToService();var context = new InstanceContext(callback);var pipeFactory =新的DuplexChannelFactory< IIpcAppToService>(上下文,新的NetNamedPipeBinding(),新的EndpointAddress("net.pipe://localhost/MyIpcAppToService"));Program.HostIpcAppToService = pipeFactory.CreateChannel();Program.HostIpcAppToService.Connect();CommAppToService.IsPipeAppToService = true;返回true;}抓住(前例外){//记录异常.Errors.LogException(ex);}返回false;} 

对于它的价值,这里是:

接口

  [ServiceContract(SessionMode = SessionMode.Allowed,CallbackContract = typeof(IIpcCallbackAppToService))]]公共接口IIpcAppToService{[OperationContract(IsOneWay = false)][FaultContractAttribute(typeof(IpcAppToServiceFault))]UInt16 GetServiceId();...} 

服务:

  [ServiceBehavior(InstanceContextMode = InstanceContextMode.PerCall)]公共类IpcAppToService:IIpcAppToService,IErrorHandler{公共静态IIpcCallbackAppToService回调{放;} = null;公共无效的OpenCallback(){IpcAppToService.Callback = OperationContext.Current.GetCallbackChannel< IIpcCallbackAppToService>();}公共无效CloseCallback(){IpcAppToService.Callback = null;}公共无效的SendMessage(字符串消息){//MessageBox.Show(message);}公共UInt16 GetServiceId(){返回Constants.My_Id_AppToService;}...} 

我的桌面WinForms应用程序中的

内部异常(请注意,没有比这更多的内部例外了.):

在本地计算机上找不到管道端点'net.pipe://localhost/MyIpcAppToService'."

为什么我继续看到此错误?

在第一个答案后更新

我要采取的方向与答案相反,但相同,即服务以 App.config 开始,而 client 使用C#代码.

可悲的是,我仍然遇到相同的错误.

修订的服务器端App.config

 <?xml version ="1.0" encoding ="utf-8"?><配置><!-部署服务库项目时,必须将配置文件的内容添加到主机的app.config文件.System.Configuration不支持库的配置文件.-><启动>< supportedRuntime版本="v4.0" sku =.NETFramework,Version = v4.6.2"/></startup>< system.serviceModel><服务>< service behaviorConfiguration ="BehaviorMyService" name ="MyService.Communication.IpcAppToService">< endpoint address ="net.pipe://localhost/MyIpcAppToService"binding ="netNamedPipeBinding"bindingConfiguration ="EndpointBindingMyAppToService"contract ="MyIpc.IIpcAppToService"/><端点地址="mex" binding ="mexHttpBinding" name ="mex" contract ="IMetadataExchange"/><主机>< baseAddresses>< add baseAddress ="http://localhost:8733/MyService/"/></baseAddresses></host></service></services><行为>< serviceBehaviors>< behavior name ="BehaviorMyService"><!-为避免泄露元数据信息,请在部署前将以下值设置为false.< serviceMetadata httpGetEnabled ="true"httpsGetEnabled ="true"/><!-要在故障中接收异常详细信息以进行调试,请将下面的值设置为true.部署前设置为false以避免泄露异常信息->< serviceDebug includeExceptionDetailInFaults ="true"/>< dataContractSerializer maxItemsInObjectGraph ="2147483647"/></行为></serviceBehaviors></行为>< bindings>< netNamedPipeBinding><!-https://docs.microsoft.com/zh-cn/dotnet/framework/configure-apps/file-schema/wcf/wshttpbinding->< binding name ="EndpointBindingMyAppToService"closeTimeout ="00:01:00"openTimeout ="00:01:00"receiveTimeout ="00:10:00"sendTimeout ="00:01:00"transactionFlow ="false"transferMode =缓冲"transactionProtocol ="OleTransactions"hostNameComparisonMode ="StrongWildcard"maxBufferPoolSize ="524288"maxBufferSize ="65536"maxConnections ="10"maxReceivedMessageSize ="2147483647"><安全模式=无">< transport protectionLevel ="None"/></security></binding></netNamedPipeBinding></bindings>< serviceHostingEnvironment aspNetCompatibilityEnabled ="true" multipleSiteBindingsEnabled ="true">< baseAddressPrefixFilters>< add prefix ="http://localhost:8733"/></baseAddressPrefixFilters></serviceHostingEnvironment></system.serviceModel>< appSettings>< add key ="countoffiles" value ="7"/><添加key ="logfilelocation" value ="abc.txt"/></appSettings></configuration> 

修订的客户端C#代码:

  var callback = new IpcCallbackAppToService();InstanceContext context = new InstanceContext(callback);NetNamedPipeBinding绑定=新的NetNamedPipeBinding();binding.Security.Mode = NetNamedPipeSecurityMode.None;EndpointAddress endpointAddress =新的EndpointAddress("net.pipe://localhost/MyIpcAppToService");var pipeFactory = new DuplexChannelFactory< IIpcAppToService>(上下文,绑定,endpointAddress);Program.HostIpcAppToService = pipeFactory.CreateChannel();Program.HostIpcAppToService.Connect();CommAppToService.IsPipeAppToService = true; 

由于EventViewer是干净的,因此该服务不会抛出任何可以检测到的异常,仅显示OnStart()成功完成的消息.我知道系统会处理 App.config 文件,就像以前遇到错误时一样, Windows Event Viewer 会一直抱怨,但现在不再抱怨了.

以下是我使用的一些Microsoft文档:



IIS站点(启用net.pipe)


客户端(控制台应用程序)

  ServiceReference1.Service1Client客户端=新的ServiceReference1.Service1Client();var result = client.GetData(34);Console.WriteLine(result); 

客户端app.config(自动生成)
我使用http地址(服务元数据GET地址 http://localhost:8733/Service1.svc?wsdl )生成配置.

 < system.serviceModel>< bindings>< netNamedPipeBinding>< binding name ="NetNamedPipeBinding_IService1"><安全模式=无"/></binding></netNamedPipeBinding></bindings><客户>< endpoint address ="net.pipe://mynetpipe/Service1.svc/MyIpcAppToService"binding ="netNamedPipeBinding" bindingConfiguration ="NetNamedPipeBinding_IService1"contract ="ServiceReference1.IService1" name ="NetNamedPipeBinding_IService1"/></client></system.serviceModel> 

请随时告诉我是否有什么可以帮忙的.

I am frustrated. Okay, here is the error.

There was no endpoint listening at net.pipe://localhost/MyIpcAppToService that could accept the message. This is often caused by an incorrect address or SOAP action. See InnerException, if present, for more details.

I finally got the App.Config file working, at least no complaints.

Current App.Config

<?xml version="1.0" encoding="utf-8"?>
<configuration>
    <!-- When deploying the service library project, the content of the config file must be added to the host's 
  app.config file. System.Configuration does not support config files for libraries. -->
    <startup>
        <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.2"/>
    </startup>
    <system.serviceModel>
        <services>
            <service behaviorConfiguration="MyServiceBehavior" name="MyService.Communication.IpcAppToService">
                <endpoint address="net.pipe://localhost/MyIpcAppToService" binding="wsDualHttpBinding" bindingConfiguration="MyAppToServiceEndpointBinding" contract="MyIpc.IIpcAppToService"/>
                <endpoint address="mex" binding="mexHttpBinding" name="mex" contract="IMetadataExchange"/>
                <host>
                    <baseAddresses>
                        <add baseAddress="http://localhost:8733/MyService/"/>
                    </baseAddresses>
                </host>
            </service>
  </services>
        <behaviors>
            <serviceBehaviors>
                <behavior name="MyServiceBehavior">
                    <!-- To avoid disclosing metadata information, set the values below to false before deployment -->
                    <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true"/>
                    <!-- To receive exception details in faults for debugging purposes, set the value below to true.  Set to false before deployment  to avoid disclosing exception information -->
                    <serviceDebug includeExceptionDetailInFaults="true"/>
                    <dataContractSerializer maxItemsInObjectGraph="2147483647"/>
                </behavior>
            </serviceBehaviors>
        </behaviors>
        <protocolMapping>
            <add scheme="http" binding="wsHttpBinding" bindingConfiguration="MyAppToServiceEndpointBinding" />
        </protocolMapping>
        <bindings>
            <wsDualHttpBinding>
                <!-- https://docs.microsoft.com/en-us/dotnet/framework/configure-apps/file-schema/wcf/wshttpbinding -->
                <binding name="MyAppToServiceEndpointBinding"
                                 transactionFlow="true"
                                 sendTimeout="00:01:00"
                                 maxReceivedMessageSize="2147483647"
                                 messageEncoding="Mtom">
                </binding>
            </wsDualHttpBinding>
        </bindings>
        <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true">
            <baseAddressPrefixFilters>
                <add prefix="http://localhost:8733"/>
            </baseAddressPrefixFilters>
        </serviceHostingEnvironment>
    </system.serviceModel>
    <appSettings>
        <add key="countoffiles" value="7"/>
        <add key="logfilelocation" value="abc.txt"/>
    </appSettings>
</configuration>

I used to have:

<endpoint address="http://localhost:8733/MyIpcAppToService" ...

and in the Windows Service OnStart() event:

(this following code is now commented out, as of this question post, as the App.config file is supposed to start the named.pipe.)

public Boolean CreatePipeServer()
{
    string eventText = $"My Service: CommAppToService::CreatePipeServer(IPC App to Service){Environment.NewLine}";
    try
    {
        if (null != this.ServiceParent.HostIpcAppToService)
            this.ServiceParent.HostIpcAppToService = null;

        string pipeBaseAddress = @"net.pipe://localhost/MyIpcAppToService";
        this.ServiceParent.HostIpcAppToService = new ServiceHost(typeof(IpcAppToService), new Uri(pipeBaseAddress));
        NetNamedPipeBinding pipeBinding = new NetNamedPipeBinding()
        {
            //ReceiveTimeout = new TimeSpan(0, 0, 0, 0, Constants.My_TimeoutMsSendReceive),
            //SendTimeout = new TimeSpan(0, 0, 0, 0, Constants.My_TimeoutMsSendReceive),
        };
        this.ServiceParent.HostIpcAppToService.AddServiceEndpoint(typeof(IIpcAppToService), pipeBinding, "MyIpcAppToService");
        this.ServiceParent.HostIpcAppToService.UnknownMessageReceived += HostIpcAppServer_UnknownMessageReceived;
        this.ServiceParent.HostIpcAppToService.Faulted += HostIpcAppServer_Faulted;
        this.ServiceParent.HostIpcAppToService.Closing += HostIpcAppServer_Closing;
        this.ServiceParent.HostIpcAppToService.Closed += HostIpcAppServer_Closed;

        this.IpcAppToService = new IpcAppToService();
        this.IpcAppToService.ApplyDispatchBehavior(this.ServiceParent.HostIpcAppToService);
        this.IpcAppToService.Validate(this.ServiceParent.HostIpcAppToService);
        this.ServiceParent.HostIpcAppToService.Open();

        return true;
    }

I read that the service will AUTOMATICALLY start services placed in the App.Config file, really the MyExeName.exe.config file. I kept looking at the code and saw that it was nearly identical, so I replaced the http:// with net.pipe://.

Sadly, old code, new code, in between code, all nothing. I keep receiving the same error.

I use the following to connect to the service from my desktop application.

public static Boolean ConnectToService()
{
    try
    {
        var callback = new IpcCallbackAppToService();
        var context = new InstanceContext(callback);
        var pipeFactory = new DuplexChannelFactory<IIpcAppToService>(context, new NetNamedPipeBinding(), new EndpointAddress("net.pipe://localhost/MyIpcAppToService"));
        Program.HostIpcAppToService = pipeFactory.CreateChannel();
        Program.HostIpcAppToService.Connect();
        CommAppToService.IsPipeAppToService = true;

        return true;
    }

    catch (Exception ex)
    {
        // Log the exception.
        Errors.LogException(ex);
    }

    return false;
}

For whatever it is worth, here is:

Interface

[ServiceContract(SessionMode = SessionMode.Allowed, CallbackContract = typeof(IIpcCallbackAppToService))]
public interface IIpcAppToService
{
    [OperationContract(IsOneWay = false)]
    [FaultContractAttribute(typeof(IpcAppToServiceFault))]
    UInt16 GetServiceId();

    ...
}

Service:

[ServiceBehavior(InstanceContextMode = InstanceContextMode.PerCall)]
public class IpcAppToService : IIpcAppToService, IErrorHandler
{
    public static IIpcCallbackAppToService Callback { get; set; } = null;

    public void OpenCallback()
    {
        IpcAppToService.Callback = OperationContext.Current.GetCallbackChannel<IIpcCallbackAppToService>();
    }

    public void CloseCallback()
    {
        IpcAppToService.Callback = null;
    }

    public void SendMessage(string message)
    {
        //MessageBox.Show(message);
    }

    public UInt16 GetServiceId()
    {
        return Constants.My_Id_AppToService;
    }

    ...
}

Inner Exception from my desktop WinForms Application (Note, there were no further inner exceptions than this one.):

"The pipe endpoint 'net.pipe://localhost/MyIpcAppToService' could not be found on your local machine."

Why do I keep seeing this error?

UPDATE AFTER 1ST ANSWER

The direction that I would like to take is opposite of the answer, yet the same, namely that the service starts with the App.config and the client uses C# code.

Sadly, I still get the same error.

Revised Server Side App.config

<?xml version="1.0" encoding="utf-8"?>
<configuration>
    <!-- When deploying the service library project, the content of the config file must be added to the host's 
  app.config file. System.Configuration does not support config files for libraries. -->
    <startup>
        <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.2"/>
    </startup>
    <system.serviceModel>
        <services>
            <service behaviorConfiguration="BehaviorMyService" name="MyService.Communication.IpcAppToService">
                <endpoint address="net.pipe://localhost/MyIpcAppToService"
                                    binding="netNamedPipeBinding"
                                    bindingConfiguration="EndpointBindingMyAppToService"
                                    contract="MyIpc.IIpcAppToService"
                                    />
                <endpoint address="mex" binding="mexHttpBinding" name="mex" contract="IMetadataExchange"/>
                <host>
                    <baseAddresses>
                        <add baseAddress="http://localhost:8733/MyService/"/>
                    </baseAddresses>
                </host>
            </service>
        </services>
        <behaviors>
            <serviceBehaviors>
                <behavior name="BehaviorMyService">
                    <!-- To avoid disclosing metadata information, set the values below to false before deployment -->
                    <serviceMetadata httpGetEnabled="true"
                                                     httpsGetEnabled="true"
                                                     />
                    <!-- To receive exception details in faults for debugging purposes, set the value below to true.  Set to false before deployment  to avoid disclosing exception information -->
                    <serviceDebug includeExceptionDetailInFaults="true"/>
                    <dataContractSerializer maxItemsInObjectGraph="2147483647"/>
                </behavior>
            </serviceBehaviors>
        </behaviors>
        <bindings>
            <netNamedPipeBinding>
                <!-- https://docs.microsoft.com/en-us/dotnet/framework/configure-apps/file-schema/wcf/wshttpbinding -->
                <binding name="EndpointBindingMyAppToService"
                                 closeTimeout="00:01:00"  
                                 openTimeout="00:01:00"   
                                 receiveTimeout="00:10:00"   
                                 sendTimeout="00:01:00"  
                                 transactionFlow="false"   
                                 transferMode="Buffered"   
                                 transactionProtocol="OleTransactions"  
                                 hostNameComparisonMode="StrongWildcard"   
                                 maxBufferPoolSize="524288"  
                                 maxBufferSize="65536"   
                                 maxConnections="10"   
                                 maxReceivedMessageSize="2147483647"
                                 >
                    <security mode="None">
                        <transport protectionLevel="None" />
                    </security>
                </binding>
            </netNamedPipeBinding>
        </bindings>
        <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true">
            <baseAddressPrefixFilters>
                <add prefix="http://localhost:8733"/>
            </baseAddressPrefixFilters>
        </serviceHostingEnvironment>
    </system.serviceModel>
    <appSettings>
        <add key="countoffiles" value="7"/>
        <add key="logfilelocation" value="abc.txt"/>
    </appSettings>
</configuration>

Revised Client Side C# Code:

var callback = new IpcCallbackAppToService();
InstanceContext context = new InstanceContext(callback);
NetNamedPipeBinding binding = new NetNamedPipeBinding();
binding.Security.Mode = NetNamedPipeSecurityMode.None;
EndpointAddress endpointAddress = new EndpointAddress("net.pipe://localhost/MyIpcAppToService");
var pipeFactory = new DuplexChannelFactory<IIpcAppToService>(context, binding, endpointAddress);
Program.HostIpcAppToService = pipeFactory.CreateChannel();
Program.HostIpcAppToService.Connect();
CommAppToService.IsPipeAppToService = true;

The service throws no exceptions that I can detect, as the EventViewer is clean, just the OnStart() successfully completed message. I know that the system processes the App.config file, as previously when I had errors, the Windows Event Viewer would keep complaining, but not anymore.

Here were some of the Microsoft docs that I used:

netNamedPipeBinding

netNamedPipeBinding2

I did try IO Ninja, but specifying \\.\pipe\MyIpcToService for File Stream, Pipe Listener, and Pipe Monitor, but nothing shows there, even when I try to connect using my WinForms desktop application, which then throws the no pipe listener found exception.

What can be the problem?

解决方案

<endpoint address="net.pipe://localhost/MyIpcAppToService" binding="wsDualHttpBinding" bindingConfiguration="MyAppToServiceEndpointBinding" contract="MyIpc.IIpcAppToService"/>

Make sure that the service address is in the same form (transport protocol) as the binding type.

  • TCP(net.tcp://localhost:8000/myservice) NetTcpBinding
  • IPC(net.pipe://localhost/mypipe) NetNamedPipeBinding
  • Http/Https(http://localhost:8000/myservice)
    Wshttpbinding,Wsdualhttpbinding,basichttpbinding

  • WebSocket(ws://localhost:3434) Nethttpbinding

  • MSMQ(net.msmq://localhost/private/myservice) NetMsmqBinding

we are supposed to use NetnamedPipeBinding for the service address. Please refer to my example.


Updated
I have a wcf service using NetNamedPipeBinding hosted in IIS, wish it is useful to you.
Server(wcf service application)

    [ServiceContract]
    public interface IService1
    {
        [OperationContract]
        string GetData(int value);
}
    public class Service1 : IService1
    {
        public string GetData(int value)
        {
            return string.Format("You entered: {0}", value);
        }
}

Web.config(Server side)

<system.serviceModel>
    <services>
      <service behaviorConfiguration="BehaviorMyService" name="WcfService1.Service1">
        <endpoint address="MyIpcAppToService"
                            binding="netNamedPipeBinding"
                            bindingConfiguration="EndpointBindingMyAppToService"
                            contract="WcfService1.IService1"
                                    />
        <endpoint address="mex" binding="mexHttpBinding" name="mex" contract="IMetadataExchange"/>
      </service>
    </services>
    <behaviors>
      <serviceBehaviors>
        <behavior name="BehaviorMyService">
          <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true"/>
          <serviceDebug includeExceptionDetailInFaults="true"/>
          <dataContractSerializer maxItemsInObjectGraph="2147483647"/>
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <bindings>
      <netNamedPipeBinding>
        <binding name="EndpointBindingMyAppToService"
                         closeTimeout="00:01:00"
                         openTimeout="00:01:00"
                         receiveTimeout="00:10:00"
                         sendTimeout="00:01:00"
                         transactionFlow="false"
                         transferMode="Buffered"
                         transactionProtocol="OleTransactions"
                         hostNameComparisonMode="StrongWildcard"
                         maxBufferPoolSize="524288"
                         maxConnections="10"
                         maxReceivedMessageSize="2147483647"
                                 >
          <security mode="None">
            <transport protectionLevel="None" />
          </security>
        </binding>
      </netNamedPipeBinding>
    </bindings>
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true">
    </serviceHostingEnvironment>
  </system.serviceModel>

Enable WCF new feature.


IIS site(enable net.pipe)


Client(console application)

  ServiceReference1.Service1Client client = new ServiceReference1.Service1Client();
    var result = client.GetData(34);
    Console.WriteLine(result);

Client app.config(auto-generated)
I use the http address(service metadata GET address http://localhost:8733/Service1.svc?wsdl) to generated the configuration.

  <system.serviceModel>
        <bindings>
            <netNamedPipeBinding>
                <binding name="NetNamedPipeBinding_IService1">
                    <security mode="None" />
                </binding>
            </netNamedPipeBinding>
        </bindings>
        <client>
            <endpoint address="net.pipe://mynetpipe/Service1.svc/MyIpcAppToService"
                binding="netNamedPipeBinding" bindingConfiguration="NetNamedPipeBinding_IService1"
                contract="ServiceReference1.IService1" name="NetNamedPipeBinding_IService1" />
        </client>
    </system.serviceModel>

Feel free to let me know if there is anything I can help with.

这篇关于Windows App中使用App.Config的WCF命名管道的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆