WCF-NetNamedPipe的ChannelFactory

时间:2012-12-10 00:31:39

标签: wcf netnamedpipebinding

更新20121214 咨询冲突服务的开发者, 他们使用 net.pipe:// echonet 作为服务地址, 并使用 DuplexChannelFactory 。 为什么它会挡住我的管?


问题:

我有一个非常简单的WCF应用程序。 服务和客户端通过NetNamedPipe通信。 但奇怪的是,有些机器可能是其他软件的原因, 导致ChannelFactory开始调用Service,抛出异常:System.ServiceModel.ProtocolException。

我怎么知道哪个应用程序捕获了我的WCF消息, 我应该如何避免这个问题。

这是例外:

System.ServiceModel.ProtocolException: The requested upgrade is not supported by 'net.pipe://localhost/xxxx/xxxx'. This could be due to mismatched bindings (for example security enabled on the client and not on the server)

Server stack trace: 
  System.ServiceModel.Channels.ConnectionUpgradeHelper.DecodeFramingFault(ClientFramingDecoder decoder, IConnection connection, Uri via, String contentType, TimeoutHelper& timeoutHelper)
  System.ServiceModel.Channels.ClientFramingDuplexSessionChannel.SendPreamble(IConnection connection, ArraySegment`1 preamble, TimeoutHelper& timeoutHelper)
  System.ServiceModel.Channels.ClientFramingDuplexSessionChannel.DuplexConnectionPoolHelper.AcceptPooledConnection(IConnection connection, TimeoutHelper& timeoutHelper)
  System.ServiceModel.Channels.ConnectionPoolHelper.EstablishConnection(TimeSpan timeout)
  System.ServiceModel.Channels.ClientFramingDuplexSessionChannel.OnOpen(TimeSpan timeout)
  System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan timeout)
  System.ServiceModel.Channels.ServiceChannel.OnOpen(TimeSpan timeout)
  System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan timeout)
  System.ServiceModel.Channels.ServiceChannel.CallOpenOnce.System.ServiceModel.Channels.ServiceChannel.ICallOnce.Call(ServiceChannel channel, TimeSpan timeout)
  System.ServiceModel.Channels.ServiceChannel.CallOnceManager.CallOnce(TimeSpan timeout, CallOnceManager cascade)
  System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs, TimeSpan timeout)
  System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage methodCall, ProxyOperationRuntime operation)
  System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage message)

Exception rethrown at [0]: 
  System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)
  System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)
  xxx.xxxxx.Communication.Contracts.IxxxComClientService.Register(ClientInfo clientInfo)
  xxx.xxxxx.Communication.xxxComClient.ActionClientRegisterOnlineClientInfo(IxxxComClientService channel)
  xxx.xxxxx.Communication.xxxComClient.ActionReceivedClientOnline(EndpointAddress endpoint)

这是我的代码'

----------------------------服务------------------ ------------

 using (var host = new ServiceHost(typeof(StringReverser), new[] { new Uri("net.pipe://localhost") }))
 {
     host.AddServiceEndpoint(typeof(IStringReverser), new NetNamedPipeBinding(), "PipeReverse");
     host.Open();

     Console.WriteLine("Service is available. Press <ENTER> to exit.");
     Console.ReadLine();

     host.Close();
  }

--------------------------客户端-------------------- -------------

var pipeFactory = new ChannelFactory<IStringReverser>(new NetNamedPipeBinding(), new EndpointAddress("net.pipe://localhost/PipeReverse"));
Console.WriteLine("pipeFactory Created. Press <Exit> to exit");
var pipeProxy = pipeFactory.CreateChannel();
Console.WriteLine("pipeProxy Created.");

while (true)
{
   var str = Console.ReadLine();
   Console.WriteLine("pipe: " + pipeProxy.ReverseString(str));
}

1 个答案:

答案 0 :(得分:0)

  • B1。该服务是Windows服务的主机,以管理员身份运行
  • B2。该服务,设置为net.pipe:// echonet作为他的地址
  • B3。我的服务,是自托管,以localuser身份运行

windowsservice&gt; localuser 所以,namedpipe将重定向到该服务。

  • S1。停止服务
  • S2。更改我的服务主机,让它托管 windowsservice。