2014-09-10 156 views
1

我是自託管的WCF服務。此服務應提供一種自定義身份驗證方法,可用於驗證將連接到它的客戶應用程序。我寫了一個自定義的用戶名/密碼驗證器,但我認爲它甚至不被使用。當我嘗試調用服務時,我收到消息「無法聯繫本地安全機構」。WCF安全失敗

的App.config:

<system.serviceModel> 
    <behaviors> 
     <serviceBehaviors> 
     <behavior name="basicHttpBehavior"> 
      <serviceMetadata httpGetEnabled="true" httpGetUrl="http://win8drewdev:8001/TestService/MEX"/> 
      <serviceCredentials> 
      <serviceCertificate findValue="0e 99 26 9b 04 20 93 86 5e 65 ad bb 7e 6d ea 62 8a 8a 07 7a" storeLocation="CurrentUser" storeName="My" x509FindType="FindBySerialNumber"/> 
      <userNameAuthentication userNamePasswordValidationMode="Custom" customUserNamePasswordValidatorType="SimpleTestValidator.WcfValidator, SimpleTestValidator"/> 
      </serviceCredentials> 
     </behavior> 
     </serviceBehaviors> 
    </behaviors> 
    <bindings> 
     <netTcpBinding> 
     <binding name="SimpleAuthBinding"> 
      <security mode="TransportWithMessageCredential"> 
      <transport clientCredentialType="None" /> 
      <message clientCredentialType="UserName"/> 
      </security> 
     </binding> 
     </netTcpBinding> 
    </bindings> 
    <services> 
     <service name="SimpleTestServer.TestService" behaviorConfiguration="basicHttpBehavior"> 
     <endpoint address="net.tcp://win8drewdev:8000/TestService" binding="netTcpBinding" bindingConfiguration="SimpleAuthBinding" contract="SimpleTestServer.ITestService" /> 
     </service> 
    </services> 
    </system.serviceModel> 

上,我做錯了什麼有什麼想法?

根據下面的答案,我附上了問題發生時的跟蹤日誌。這似乎表明,客戶端正在發生某些事情,但我仍然不確定這會讓我感到什麼。

<E2ETraceEvent xmlns="http://schemas.microsoft.com/2004/06/E2ETraceEvent"> 
    <System xmlns="http://schemas.microsoft.com/2004/06/windows/eventlog/system"> 
     <EventID>131075</EventID> 
     <Type>3</Type> 
     <SubType Name="Error">0</SubType> 
     <Level>2</Level> 
     <TimeCreated SystemTime="2014-09-11T12:13:38.0193252Z" /> 
     <Source Name="System.ServiceModel" /> 
     <Correlation ActivityID="{3c51d0c7-20ae-4401-b57b-771ebdbb8f83}" /> 
     <Execution ProcessName="SimpleTestServer.vshost" ProcessID="1572" ThreadID="18" /> 
     <Channel /> 
     <Computer>WIN8DREWDEV</Computer> 
    </System> 
    <ApplicationData> 
     <TraceData> 
      <DataItem> 
       <TraceRecord xmlns="http://schemas.microsoft.com/2004/10/E2ETraceEvent/TraceRecord" Severity="Error"> 
        <TraceIdentifier>http://msdn.microsoft.com/en-US/library/System.ServiceModel.Diagnostics.ThrowingException.aspx</TraceIdentifier> 
        <Description>Throwing an exception.</Description> 
        <AppDomain>SimpleTestServer.vshost.exe</AppDomain> 
        <Exception> 
         <ExceptionType>System.ServiceModel.CommunicationException, System.ServiceModel, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</ExceptionType> 
         <Message>The socket connection was aborted. This could be caused by an error processing your message or a receive timeout being exceeded by the remote host, or an underlying network resource issue. Local socket timeout was '00:10:00'.</Message> 
         <StackTrace> at System.ServiceModel.Channels.SocketConnection.EndRead() 
    at System.ServiceModel.Channels.DelegatingConnection.EndRead() 
    at System.ServiceModel.Channels.TracingConnection.EndRead() 
    at System.ServiceModel.Channels.ConnectionStream.ReadAsyncResult.HandleIO(IConnection connection) 
    at System.ServiceModel.Channels.ConnectionStream.IOAsyncResult.OnAsyncIOComplete(Object state) 
    at System.ServiceModel.Channels.TracingConnection.TracingConnectionState.ExecuteCallback() 
    at System.ServiceModel.Channels.TracingConnection.WaitCallback(Object state) 
    at System.ServiceModel.Channels.SocketConnection.FinishRead() 
    at System.ServiceModel.Channels.SocketConnection.OnReceiveAsync(Object sender, SocketAsyncEventArgs eventArgs) 
    at System.ServiceModel.Channels.SocketConnection.OnReceiveAsyncCompleted(Object sender, SocketAsyncEventArgs e) 
    at System.Net.Sockets.SocketAsyncEventArgs.OnCompleted(SocketAsyncEventArgs e) 
    at System.Net.Sockets.SocketAsyncEventArgs.FinishOperationAsyncFailure(SocketError socketError, Int32 bytesTransferred, SocketFlags flags) 
    at System.Net.Sockets.SocketAsyncEventArgs.CompletionPortCallback(UInt32 errorCode, UInt32 numBytes, NativeOverlapped* nativeOverlapped) 
    at System.Threading._IOCompletionCallback.PerformIOCompletionCallback(UInt32 errorCode, UInt32 numBytes, NativeOverlapped* pOVERLAP) 
</StackTrace> 
         <ExceptionString>System.ServiceModel.CommunicationException: The socket connection was aborted. This could be caused by an error processing your message or a receive timeout being exceeded by the remote host, or an underlying network resource issue. Local socket timeout was '00:10:00'. ---&amp;gt; System.Net.Sockets.SocketException: An existing connection was forcibly closed by the remote host 
    at System.ServiceModel.Channels.SocketConnection.HandleReceiveAsyncCompleted() 
    at System.ServiceModel.Channels.SocketConnection.OnReceiveAsync(Object sender, SocketAsyncEventArgs eventArgs) 
    --- End of inner exception stack trace ---</ExceptionString> 
         <InnerException> 
          <ExceptionType>System.Net.Sockets.SocketException, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</ExceptionType> 
          <Message>An existing connection was forcibly closed by the remote host</Message> 
          <StackTrace> at System.ServiceModel.Channels.SocketConnection.HandleReceiveAsyncCompleted() 
    at System.ServiceModel.Channels.SocketConnection.OnReceiveAsync(Object sender, SocketAsyncEventArgs eventArgs)</StackTrace> 
          <ExceptionString>System.Net.Sockets.SocketException (0x80004005): An existing connection was forcibly closed by the remote host 
    at System.ServiceModel.Channels.SocketConnection.HandleReceiveAsyncCompleted() 
    at System.ServiceModel.Channels.SocketConnection.OnReceiveAsync(Object sender, SocketAsyncEventArgs eventArgs)</ExceptionString> 
          <NativeErrorCode>2746</NativeErrorCode> 
         </InnerException> 
        </Exception> 
       </TraceRecord> 
      </DataItem> 
     </TraceData> 
    </ApplicationData> 
</E2ETraceEvent> 

下面是來自客戶端的跟蹤活動:

<E2ETraceEvent xmlns="http://schemas.microsoft.com/2004/06/E2ETraceEvent"> 
    <System xmlns="http://schemas.microsoft.com/2004/06/windows/eventlog/system"> 
    <EventID>131075</EventID> 
    <Type>3</Type> 
    <SubType Name="Error">0</SubType> 
    <Level>2</Level> 
    <TimeCreated SystemTime="2014-09-11T12:53:17.8882554Z" /> 
    <Source Name="System.ServiceModel" /> 
    <Correlation ActivityID="{b3316328-1b82-4aa3-b45c-ba8e7fd42c20}" /> 
    <Execution ProcessName="SimpleWcfClient.vshost" ProcessID="1816" ThreadID="9" /> 
    <Channel /> 
    <Computer>USSDEV08WS02</Computer> 
    </System> 
    <ApplicationData> 
    <TraceData> 
     <DataItem> 
     <TraceRecord xmlns="http://schemas.microsoft.com/2004/10/E2ETraceEvent/TraceRecord" Severity="Error"> 
      <TraceIdentifier>http://msdn.microsoft.com/en-US/library/System.ServiceModel.Diagnostics.ThrowingException.aspx</TraceIdentifier> 
      <Description>Throwing an exception.</Description> 
      <AppDomain>SimpleWcfClient.vshost.exe</AppDomain> 
      <Exception> 
      <ExceptionType>System.ServiceModel.Security.SecurityNegotiationException, System.ServiceModel, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</ExceptionType> 
      <Message>A call to SSPI failed, see inner exception.</Message> 
      <StackTrace> 
       at System.ServiceModel.Channels.SslStreamSecurityUpgradeInitiator.OnInitiateUpgrade(Stream stream, SecurityMessageProperty&amp;amp; remoteSecurity) 
       at System.ServiceModel.Channels.StreamSecurityUpgradeInitiatorBase.InitiateUpgrade(Stream stream) 
       at System.ServiceModel.Channels.ConnectionUpgradeHelper.InitiateUpgrade(StreamUpgradeInitiator upgradeInitiator, IConnection&amp;amp; connection, ClientFramingDecoder decoder, IDefaultCommunicationTimeouts defaultTimeouts, TimeoutHelper&amp;amp; timeoutHelper) 
       at System.ServiceModel.Channels.ClientFramingDuplexSessionChannel.SendPreamble(IConnection connection, ArraySegment`1 preamble, TimeoutHelper&amp;amp; timeoutHelper) 
       at System.ServiceModel.Channels.ClientFramingDuplexSessionChannel.DuplexConnectionPoolHelper.AcceptPooledConnection(IConnection connection, TimeoutHelper&amp;amp; 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.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor) 
       at System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj, Object[] parameters, Object[] arguments) 
       at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture) 
       at System.ServiceModel.Channels.ServiceChannelProxy.ExecuteMessage(Object target, IMethodCallMessage methodCall) 
       at System.ServiceModel.Channels.ServiceChannelProxy.InvokeChannel(IMethodCallMessage methodCall) 
       at System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage message) 
       at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData&amp;amp; msgData, Int32 type) 
       at System.ServiceModel.ICommunicationObject.Open(TimeSpan timeout) 
       at System.ServiceModel.Channels.SecurityChannelFactory`1.ClientSecurityChannel`1.OnOpen(TimeSpan timeout) 
       at System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan timeout) 
       at System.ServiceModel.Security.SecuritySessionSecurityTokenProvider.DoOperation(SecuritySessionOperation operation, EndpointAddress target, Uri via, SecurityToken currentToken, TimeSpan timeout) 
       at System.ServiceModel.Security.SecuritySessionSecurityTokenProvider.GetTokenCore(TimeSpan timeout) 
       at System.IdentityModel.Selectors.SecurityTokenProvider.GetToken(TimeSpan timeout) 
       at System.ServiceModel.Security.SecuritySessionClientSettings`1.ClientSecuritySessionChannel.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.ServiceChannelProxy.InvokeService(IMethodCallMessage methodCall, ProxyOperationRuntime operation) 
       at System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage message) 
       at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData&amp;amp; msgData, Int32 type) 
       at SimpleWcfClient.TestService.ITestService.Hello() 
       at SimpleWcfClient.Program.Main(String[] args) 
       at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args) 
       at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args) 
       at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly() 
       at System.Threading.ThreadHelper.ThreadStart_Context(Object state) 
       at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx) 
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx) 
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state) 
       at System.Threading.ThreadHelper.ThreadStart() 
      </StackTrace> 
      <ExceptionString> 
       System.ServiceModel.Security.SecurityNegotiationException: A call to SSPI failed, see inner exception. ---&amp;gt; System.Security.Authentication.AuthenticationException: A call to SSPI failed, see inner exception. ---&amp;gt; System.ComponentModel.Win32Exception: The Local Security Authority cannot be contacted 
       --- End of inner exception stack trace --- 
       at System.Net.Security.SslState.StartSendAuthResetSignal(ProtocolToken message, AsyncProtocolRequest asyncRequest, Exception exception) 
       at System.Net.Security.SslState.CheckCompletionBeforeNextReceive(ProtocolToken message, AsyncProtocolRequest asyncRequest) 
       at System.Net.Security.SslState.StartSendBlob(Byte[] incoming, Int32 count, AsyncProtocolRequest asyncRequest) 
       at System.Net.Security.SslState.ProcessReceivedBlob(Byte[] buffer, Int32 count, AsyncProtocolRequest asyncRequest) 
       at System.Net.Security.SslState.StartReadFrame(Byte[] buffer, Int32 readBytes, AsyncProtocolRequest asyncRequest) 
       at System.Net.Security.SslState.StartReceiveBlob(Byte[] buffer, AsyncProtocolRequest asyncRequest) 
       at System.Net.Security.SslState.CheckCompletionBeforeNextReceive(ProtocolToken message, AsyncProtocolRequest asyncRequest) 
       at System.Net.Security.SslState.StartSendBlob(Byte[] incoming, Int32 count, AsyncProtocolRequest asyncRequest) 
       at System.Net.Security.SslState.ForceAuthentication(Boolean receiveFirst, Byte[] buffer, AsyncProtocolRequest asyncRequest) 
       at System.Net.Security.SslState.ProcessAuthentication(LazyAsyncResult lazyResult) 
       at System.Net.Security.SslStream.AuthenticateAsClient(String targetHost, X509CertificateCollection clientCertificates, SslProtocols enabledSslProtocols, Boolean checkCertificateRevocation) 
       at System.ServiceModel.Channels.SslStreamSecurityUpgradeInitiator.OnInitiateUpgrade(Stream stream, SecurityMessageProperty&amp;amp; remoteSecurity) 
       --- End of inner exception stack trace --- 
      </ExceptionString> 
      <InnerException> 
       <ExceptionType>System.Security.Authentication.AuthenticationException, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</ExceptionType> 
       <Message>A call to SSPI failed, see inner exception.</Message> 
       <StackTrace> 
       at System.Net.Security.SslState.StartSendAuthResetSignal(ProtocolToken message, AsyncProtocolRequest asyncRequest, Exception exception) 
       at System.Net.Security.SslState.CheckCompletionBeforeNextReceive(ProtocolToken message, AsyncProtocolRequest asyncRequest) 
       at System.Net.Security.SslState.StartSendBlob(Byte[] incoming, Int32 count, AsyncProtocolRequest asyncRequest) 
       at System.Net.Security.SslState.ProcessReceivedBlob(Byte[] buffer, Int32 count, AsyncProtocolRequest asyncRequest) 
       at System.Net.Security.SslState.StartReadFrame(Byte[] buffer, Int32 readBytes, AsyncProtocolRequest asyncRequest) 
       at System.Net.Security.SslState.StartReceiveBlob(Byte[] buffer, AsyncProtocolRequest asyncRequest) 
       at System.Net.Security.SslState.CheckCompletionBeforeNextReceive(ProtocolToken message, AsyncProtocolRequest asyncRequest) 
       at System.Net.Security.SslState.StartSendBlob(Byte[] incoming, Int32 count, AsyncProtocolRequest asyncRequest) 
       at System.Net.Security.SslState.ForceAuthentication(Boolean receiveFirst, Byte[] buffer, AsyncProtocolRequest asyncRequest) 
       at System.Net.Security.SslState.ProcessAuthentication(LazyAsyncResult lazyResult) 
       at System.Net.Security.SslStream.AuthenticateAsClient(String targetHost, X509CertificateCollection clientCertificates, SslProtocols enabledSslProtocols, Boolean checkCertificateRevocation) 
       at System.ServiceModel.Channels.SslStreamSecurityUpgradeInitiator.OnInitiateUpgrade(Stream stream, SecurityMessageProperty&amp;amp; remoteSecurity) 
       </StackTrace> 
       <ExceptionString> 
       System.Security.Authentication.AuthenticationException: A call to SSPI failed, see inner exception. ---&amp;gt; System.ComponentModel.Win32Exception: The Local Security Authority cannot be contacted 
       --- End of inner exception stack trace --- 
       at System.Net.Security.SslState.StartSendAuthResetSignal(ProtocolToken message, AsyncProtocolRequest asyncRequest, Exception exception) 
       at System.Net.Security.SslState.CheckCompletionBeforeNextReceive(ProtocolToken message, AsyncProtocolRequest asyncRequest) 
       at System.Net.Security.SslState.StartSendBlob(Byte[] incoming, Int32 count, AsyncProtocolRequest asyncRequest) 
       at System.Net.Security.SslState.ProcessReceivedBlob(Byte[] buffer, Int32 count, AsyncProtocolRequest asyncRequest) 
       at System.Net.Security.SslState.StartReadFrame(Byte[] buffer, Int32 readBytes, AsyncProtocolRequest asyncRequest) 
       at System.Net.Security.SslState.StartReceiveBlob(Byte[] buffer, AsyncProtocolRequest asyncRequest) 
       at System.Net.Security.SslState.CheckCompletionBeforeNextReceive(ProtocolToken message, AsyncProtocolRequest asyncRequest) 
       at System.Net.Security.SslState.StartSendBlob(Byte[] incoming, Int32 count, AsyncProtocolRequest asyncRequest) 
       at System.Net.Security.SslState.ForceAuthentication(Boolean receiveFirst, Byte[] buffer, AsyncProtocolRequest asyncRequest) 
       at System.Net.Security.SslState.ProcessAuthentication(LazyAsyncResult lazyResult) 
       at System.Net.Security.SslStream.AuthenticateAsClient(String targetHost, X509CertificateCollection clientCertificates, SslProtocols enabledSslProtocols, Boolean checkCertificateRevocation) 
       at System.ServiceModel.Channels.SslStreamSecurityUpgradeInitiator.OnInitiateUpgrade(Stream stream, SecurityMessageProperty&amp;amp; remoteSecurity) 
       </ExceptionString> 
       <InnerException> 
       <ExceptionType>System.ComponentModel.Win32Exception, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</ExceptionType> 
       <Message>The Local Security Authority cannot be contacted</Message> 
       <StackTrace> 
        at System.ServiceModel.Channels.SslStreamSecurityUpgradeInitiator.OnInitiateUpgrade(Stream stream, SecurityMessageProperty&amp;amp; remoteSecurity) 
        at System.ServiceModel.Channels.StreamSecurityUpgradeInitiatorBase.InitiateUpgrade(Stream stream) 
        at System.ServiceModel.Channels.ConnectionUpgradeHelper.InitiateUpgrade(StreamUpgradeInitiator upgradeInitiator, IConnection&amp;amp; connection, ClientFramingDecoder decoder, IDefaultCommunicationTimeouts defaultTimeouts, TimeoutHelper&amp;amp; timeoutHelper) 
        at System.ServiceModel.Channels.ClientFramingDuplexSessionChannel.SendPreamble(IConnection connection, ArraySegment`1 preamble, TimeoutHelper&amp;amp; timeoutHelper) 
        at System.ServiceModel.Channels.ClientFramingDuplexSessionChannel.DuplexConnectionPoolHelper.AcceptPooledConnection(IConnection connection, TimeoutHelper&amp;amp; 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.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor) 
        at System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj, Object[] parameters, Object[] arguments) 
        at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture) 
        at System.ServiceModel.Channels.ServiceChannelProxy.ExecuteMessage(Object target, IMethodCallMessage methodCall) 
        at System.ServiceModel.Channels.ServiceChannelProxy.InvokeChannel(IMethodCallMessage methodCall) 
        at System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage message) 
        at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData&amp;amp; msgData, Int32 type) 
        at System.ServiceModel.ICommunicationObject.Open(TimeSpan timeout) 
        at System.ServiceModel.Channels.SecurityChannelFactory`1.ClientSecurityChannel`1.OnOpen(TimeSpan timeout) 
        at System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan timeout) 
        at System.ServiceModel.Security.SecuritySessionSecurityTokenProvider.DoOperation(SecuritySessionOperation operation, EndpointAddress target, Uri via, SecurityToken currentToken, TimeSpan timeout) 
        at System.ServiceModel.Security.SecuritySessionSecurityTokenProvider.GetTokenCore(TimeSpan timeout) 
        at System.IdentityModel.Selectors.SecurityTokenProvider.GetToken(TimeSpan timeout) 
        at System.ServiceModel.Security.SecuritySessionClientSettings`1.ClientSecuritySessionChannel.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.ServiceChannelProxy.InvokeService(IMethodCallMessage methodCall, ProxyOperationRuntime operation) 
        at System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage message) 
        at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData&amp;amp; msgData, Int32 type) 
        at SimpleWcfClient.TestService.ITestService.Hello() 
        at SimpleWcfClient.Program.Main(String[] args) 
        at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args) 
        at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args) 
        at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly() 
        at System.Threading.ThreadHelper.ThreadStart_Context(Object state) 
        at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx) 
        at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx) 
        at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state) 
        at System.Threading.ThreadHelper.ThreadStart() 
       </StackTrace> 
       <ExceptionString>System.ComponentModel.Win32Exception (0x80004005): The Local Security Authority cannot be contacted</ExceptionString> 
       <NativeErrorCode>80090304</NativeErrorCode> 
       </InnerException> 
      </InnerException> 
      </Exception> 
     </TraceRecord> 
     </DataItem> 
    </TraceData> 
    </ApplicationData> 
</E2ETraceEvent> 

對於任何人誰碰到這個崗位絆倒,我已經找到了答案,這是不以任何上述的。由於它是一個封閉的系統,我正在創建自己的證書以供使用,我們不希望爲涉及的每臺計算機購買證書,並且計算機的位置禁止使用Windows證書頒發機構。出於某種原因(我還在試圖弄清楚),當我從一臺計算機請求證書時,在另一臺計算機上簽名,然後將其存儲在原始計算機上,則無法找到與證書關聯的私鑰。我不確定發生這種情況的具體原因,但這是由於WCF無法使用密鑰來加密/解密數據而導致此問題的原因。

+0

http://stackoverflow.com/questions/15915545/how-to-implement-webservicehost-authentication? – 2014-09-10 20:35:11

+0

我不確定這個鏈接有什麼用處? – 2014-09-11 11:16:27

回答

1

有幾件事情可以做。

首先,

嘗試在findValue="0e 99 26 9b 04 20 93 86 5e 65 ad bb 7e 6d ea 62 8a 8a 07 7a"

第二除去空間,

請在客戶端的app.config的行爲進行以下更改和安裝的服務證書客戶端機器的存儲TrustedPeople

 <behavior name="ClientCertificateBehavior"> 
      <dataContractSerializer maxItemsInObjectGraph="2147483647" /> 
      <clientCredentials> 
      <serviceCertificate> 
       <defaultCertificate x509FindType="FindByThumbprint" 
       storeName="TrustedPeople" 
       storeLocation="LocalMachine" 
       findValue="9d4c41cde9d2b82d751a5416fd2eb6df98d3b7545"/> 
       <authentication certificateValidationMode ="PeerOrChainTrust"/> 
      </serviceCertificate> 
      </clientCredentials> 
     </behavior> 

三, 使用在服務配置和應用程序配置自定義綁定

 <customBinding> 
     <binding name="UserNameCertificate" receiveTimeout="00:10:00" sendTimeout="00:10:00"> 
      <reliableSession ordered="true" inactivityTimeout="01:00:00" maxPendingChannels="128" flowControlEnabled="true" /> 
      <binaryMessageEncoding> 
      <readerQuotas maxDepth="32" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="4096" maxNameTableCharCount="16384" /> 
      </binaryMessageEncoding> 
      <security authenticationMode="SecureConversation" requireDerivedKeys ="true"> 
      <secureConversationBootstrap authenticationMode="UserNameForCertificate" /> 
      </security> 
      <tcpTransport maxPendingConnections="100" listenBacklog="100" hostNameComparisonMode="StrongWildcard" transferMode="Buffered" maxBufferPoolSize="1073741824" maxBufferSize="1073741824" maxReceivedMessageSize="1073741824" /> 
     </binding> 
     </customBinding> 

最後, 如果問題仍然存在,請嘗試安全關閉爲無並檢查它是否作品。如果有,它可能是一個域問題。 (不要忘了將tcp端口添加到防火牆例外。)

啓動WCF跟蹤,可以讓您更深入地瞭解實際問題。請參考Link

+0

沒有任何改變。仍然得到「本地安全機構不能聯繫。「當然,它確實可以在安全關閉的情況下工作,但是仍然沒有告訴我爲什麼它不能在打開安全的情況下工作,這正是我需要的。 – 2014-09-11 12:24:49

+0

是否可以調試代碼並在自定義中設置斷點驗證器?如果沒有通過身份驗證調用來達到,設置是有點buggy。 – Codor 2014-09-11 12:54:33

+0

我試過了,並且自定義驗證器從來沒有被調用過它在SSPI協商期間由於某種原因中斷 – 2014-09-11 12:56:28