2015-02-08 101 views
1

我有兩個不同的進程(在同一個會話上,兩個都沒有提升)在自託管服務(託管在服務器進程中)上使用命名管道進行通信。 在極少數情況下(2-3%的用戶),客戶端將無法連接服務器。WCF命名管道未知錯誤

它只發生在UAC下,並沒有提升。要清楚的是,在大多數情況下,應用程序對於使用UAC和未升級會話的用戶來說工作得很好。

我發現,作爲管理員運行所有內容可以解決此問題,但我不想走這條路。另外,將通信改爲netTcp也可以解決它,但它會提示我的用戶使用Windows防火牆對話框,這對我來說是不可接受的。

我不明白爲什麼發生這種情況或如何解決它。我看到很多關於創建管道所需權限的文章,但就我所見,我不需要全局管道,只需要一個本地管道,而不需要UAC off/elevation /特定對象。

服務器將不顯示錯誤,通常採取行動,但客戶端將顯示此:

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

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

Exception rethrown at [0]: 
    at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg) 
    at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type) 
    at MyApp.BL.Interfaces.Service.IWCFClientServiceAPI.Initialize() 
    at MyApp.Main.attemptConnection(WCFStoreAPIClient& i_WCFClientServiceAPI, IWCFClientCallbackAPI& i_WCFClientCallbackAPI) 

服務器配置:

<?xml version="1.0"?> 
<configuration> 
    <configSections> 
    <sectionGroup name="userSettings" type="System.Configuration.UserSettingsGroup, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"> 
     <section name="MyApp.Client.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" allowExeDefinition="MachineToLocalUser" requirePermission="false"/> 
    </sectionGroup> 
    </configSections> 
    <runtime> 
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"> 
     <probing privatePath="Locales"/> 
    </assemblyBinding> 
    </runtime> 
    <system.serviceModel> 
    <bindings> 
     <netNamedPipeBinding> 
     <binding name="NPBinding_IWCFClientServiceAPI" transactionProtocol="OleTransactions" receiveTimeout="infinite" maxConnections="200" maxBufferSize="3145728" maxBufferPoolSize="3145728" maxReceivedMessageSize="3145728"/> 
     </netNamedPipeBinding> 
    </bindings> 
    <services> 
     <service 
      name="MyApp.Client.Core.Managers.WCFClientService" 
      behaviorConfiguration="WCFClientServiceBehavior"> 
     <host> 
      <baseAddresses> 
      <add baseAddress="net.pipe://localhost/MyAppServices/" /> 
      </baseAddresses> 
     </host> 
     <endpoint address="" binding="netNamedPipeBinding" contract="MyApp.BL.Interfaces.Service.IWCFClientServiceAPI" bindingConfiguration="NPBinding_IWCFClientServiceAPI"> 
     </endpoint> 
     </service> 
    </services> 
    <behaviors> 
     <serviceBehaviors> 
     <behavior name="WCFClientServiceBehavior"> 
      <serviceMetadata httpGetEnabled="False"/> 
      <serviceDebug includeExceptionDetailInFaults="False" /> 
     </behavior> 
     </serviceBehaviors> 
    </behaviors> 
    </system.serviceModel> 
</configuration> 

客戶端配置:

<?xml version="1.0" encoding="utf-8" ?> 
<configuration> 
    <system.serviceModel> 
    <bindings> 
     <netNamedPipeBinding> 
     <binding name="NPBinding_IWCFClientServiceAPI" transactionProtocol="OleTransactions" receiveTimeout="infinite" maxConnections="200" maxBufferSize="3145728" maxBufferPoolSize="3145728" maxReceivedMessageSize="3145728"/> 
     </netNamedPipeBinding> 
    </bindings> 
    <client> 
     <endpoint address="net.pipe://localhost/MyAppServices" 
       binding="netNamedPipeBinding" 
       bindingConfiguration="NPBinding_IWCFClientServiceAPI" 
       contract="MyApp.BL.Interfaces.Service.IWCFClientServiceAPI" 
       name="NPBinding_IWCFClientServiceAPI"> 
     <headers> 
      <ClientIdentification>MyAppStore</ClientIdentification> 
     </headers> 
     </endpoint> 
    </client> 
    </system.serviceModel> 
</configuration> 
+0

你確定你已經啓用net.pipe綁定在iis網站上的服務託管? – 2015-02-08 17:09:22

+0

該服務是自託管的。我會更新我的帖子。 – Tsury 2015-02-08 17:10:58

回答

0

我使用命名管道進行進程間通信的類似問題。當服務器應用程序使用「以管理員身份運行」運行時,客戶端應用程序只能連接到服務器應用程序,否則我會從客戶端應用程序獲取EndpointNotFoundException。

This post described the core of the problem。如果已經有一個命名管道,其端點爲使用提升權限創建的「net.pipe:// localhost /」,則客戶端將無法連接到非高端端點,如「net.pipe:// localhost/SomethingElse」。

post helped me find the named pipes已在我的系統上打開。下載Sysinternals Suite,然後在提升的命令提示符下使用Handle.exe來搜索打開的命名管道。

handle net.pipe 

管道的名稱使用Base64編碼。

net.pipe:E<Base64EncodedValue> 
net.pipe:EbmV0LnBpcGU6Ly8rL1RSQURFU0VSVklDRS9TRVJWSUNFMS8= 

我用這個link to decode the Base64 value

bmV0LnBpcGU6Ly8rL1RSQURFU0VSVklDRS9TRVJWSUNFMS8= 
net.pipe://+/TRADESERVICE/SERVICE1/ 

命名管道是造成這個問題是

net.pipe:EbmV0LnBpcGU6Ly8rLw== 

哪個解碼

net.pipe://+/ 

注:+或*可以在本地主機

殺違規通配符進程,或讓它指定一個更具體的端點(如net.pipe:// localhost/SomethingElse)解決了 問題。

+0

呵呵。我實際上已經忘記了這個問題。我最終完全放棄了WCF並轉移到命名管道。你說的沒錯,這個違規流程是Razer Synapse(Razer Wizard Service)的一部分。謝謝。 – Tsury 2015-10-08 16:06:06