2012-01-09 6 views
8

Win-form 응용 프로그램을 사용하여 WCF 서비스에 연결할 수 있지만 Windows 서비스에서는 연결할 수 없습니다. System.Security.Authentication.InvalidCredentialException : 서버 클라이언트 자격 증명을 거부했습니다 내가 프록시() 사격 할 때마다이 서버는 가 서버가 클라이언트 자격 증명 인 WCF를 Windows 서비스로 거부했습니다.

내부 예외가 클라이언트 자격 증명

을 거부했습니다

다음과 같은 오류를 발생 .
---> System.ComponentModel.Win32Exception : 로그온 시도가 실패
--- 내부 예외 스택 추적의 끝 --- System.Net.Security.NegoState.ProcessAuthentication에서
(LazyAsyncResult lazyResult)
에서 System.Net.Security.NegotiateStream.AuthenticateAsClient (NetworkCredential 자격 증명,의 ChannelBinding 바인딩, 문자열에서 targetName, ProtectionLevel requiredProtectionLevel, TokenImpersonationLevel allowedImpersonationLevel)
System.Net.Security.NegotiateStream.AuthenticateAsClient (NetworkCredential 자격 증명, 문자열에서 targetName에서 보호 따라서, System.ServiceModel.Channels.WindowsStreamSecurityUpgradeProvider.WindowsStreamSecurityUpgradeInitiator.OnInitiateUpgrade에서 ionLevel requiredProtectionLevel, TokenImpersonationLevel allowedImpersonationLevel)
(스트림 스트림, SecurityMessageProperty & remoteSecurity는)

솔루션을 찾고 시도, 그러나 아무도 내 요구 사항을 피팅 없다 게시했습니다.

도와주세요 ...

업데이트 1 :. A.R @

, 시도

client.ClientCredentials.Windows.AllowedImpersonationLevel = 
    System.Security.Principal.TokenImpersonationLevel.Impersonation; 

를 사용하고 있지만 아무 소용.

업데이트 2 :

WCF 서비스 구성

<system.serviceModel> 
    <diagnostics performanceCounters="All" /> 
    <bindings> 
     <netTcpBinding> 
     <binding name="myBindingForLargeData" maxReceivedMessageSize="5242880" maxConnections="10"> 
      <readerQuotas maxDepth="64" maxStringContentLength="5242880" maxArrayLength="16384" 
         maxBytesPerRead="4096" maxNameTableCharCount="16384"/> 
     </binding> 
     </netTcpBinding> 
    </bindings> 
    <services> 
     <service behaviorConfiguration="WCFService.ServiceBehavior" 
     name="WCFService.CollectorService"> 
     <endpoint address="" binding="netTcpBinding" bindingConfiguration="myBindingForLargeData" 
      name="netTcpEndPoint" contract="WCFService.ICollectorService" /> 
     <endpoint address="mex" binding="mexTcpBinding" bindingConfiguration="" 
      name="mexTcpEndPoint" contract="IMetadataExchange" /> 
     <host> 
      <baseAddresses> 
      <add baseAddress="net.tcp://localhost:8010/WCFService.CollectorService/" /> 
      </baseAddresses> 
     </host> 
     </service> 
    </services> 
    <behaviors> 
     <serviceBehaviors> 
     <behavior name="WCFService.ServiceBehavior"> 
      <serviceMetadata httpGetEnabled="False"/> 
      <serviceDebug includeExceptionDetailInFaults="True" /> 
      <serviceThrottling 
      maxConcurrentCalls="32" 
      maxConcurrentSessions="32" 
      maxConcurrentInstances="32" 
      /> 
     </behavior> 
     </serviceBehaviors> 
    </behaviors> 
</system.serviceModel> 

답변

4

귀하의 도움에 감사드립니다. 나는 몇 가지 연구 및 시험 n 오류 방법의 몇 일 후 답변을 가지고 :) 글쎄, 나는 늦게 답변을 게시 할 것을 알고 있지만, 나는 그것보다 늦게 생각하지 않는다.

그래서 여기

<system.serviceModel> 
    <bindings> 
     <netTcpBinding> 
     <binding name="netTcpEndPoint" closeTimeout="00:01:00" openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:10:00" transactionFlow="false" transferMode="Buffered" transactionProtocol="OleTransactions" hostNameComparisonMode="StrongWildcard" listenBacklog="10" maxBufferPoolSize="5242880" maxBufferSize="5242880" maxConnections="15" maxReceivedMessageSize="5242880"> 
      <readerQuotas maxDepth="32" maxStringContentLength="5242880" maxArrayLength="16384" maxBytesPerRead="4096" maxNameTableCharCount="16384" /> 
      <reliableSession ordered="true" inactivityTimeout="00:10:00" enabled="false" /> 
     <security mode="Transport"> 
      <transport clientCredentialType="Windows" protectionLevel="EncryptAndSign" /> 
      <message clientCredentialType="Windows" /> 
      </security> 
     </binding> 
     </netTcpBinding> 
    </bindings> 
    <client> 
     <endpoint address="net.tcp://xx.xx.xx.xx:8010/WCFService.CollectorService/" binding="netTcpBinding" bindingConfiguration="netTcpEndPoint" contract="CloudAdapter.CloudCollectorService.ICollectorService" name="netTcpEndPoint"> 
     </endpoint> 
    </client> 
    </system.serviceModel> 

아래와 같이 내가 내 설정 파일에 일부 변경 (모두 클라이언트 & 서버) 내가 <security> 태그를 추가 클라이언트 측에

했습니다 솔루션

입니다 또한 아래와 같이 서버 측 (WCF 서비스 구성)에 동일한 태그를 추가했습니다.

<bindings> 
    <netTcpBinding> 
    <binding name="myBindingForLargeData" maxReceivedMessageSize="5242880" maxConnections="10"> 
     <readerQuotas maxDepth="64" maxStringContentLength="5242880" maxArrayLength="16384" 
        maxBytesPerRead="4096" maxNameTableCharCount="16384"/> 
     <security mode="Transport"> 
     <transport clientCredentialType="Windows" protectionLevel="EncryptAndSign" /> 
     <message clientCredentialType="Windows" /> 
     </security> 
    </binding> 
    </netTcpBinding> 
</bindings> 
,

희망이 도움

그래서 키가 클라이언트와 서버 구성 파일을 통해 <security> 태그를 동일하게하는 것입니다 필요 :)에있는 사람.

4

기본적으로 무슨 일이 일어나고 있는지 윈폼에서 호출 할 때 당신이 가진 것처럼 전화 서비스가 적절한 자격 증명이없는 것입니다. 당신이 필요로하는 것은 가장 (impersonation)입니다. 약간의 설정이 필요하고 성가신 일이지만 작동 할 것입니다.

운 좋게 MSDN에는 멋진 연습이 있습니다.
http://msdn.microsoft.com/en-us/library/ms731090.aspx

여기에 주제에 대한 좀 더 일반적인 정보가있다 :
http://msdn.microsoft.com/en-us/library/ms730088.aspx

UPDATE :
설정 가장 플래그는 충분하지 않습니다. 실제로 작동하도록 자격 증명을 가장해야합니다.예 :

// Let's assume that this code is run inside of the calling service. 
    var winIdentity = ServiceSecurityContext.Current.WindowsIdentity; 
    using (var impContext = winIdentity.Impersonate()) 
    { 
    // So this would be the service call that is failing otherwise. 
    return MyService.MyServiceCall(); 
    } 
+0

질문이 업데이트되었습니다. – Bravo

+0

을 확인하십시오. 실제로 가장 할 사람을 말해야합니다. 플래그를 설정하고 마술처럼 누군가를 사칭 할 것으로 기대할 수는 없습니다. 두 번째 링크에있는 자료를 읽으십시오. –

1

WCF 서비스에서 사용하는 인증 모드는 무엇입니까? Windows 서비스가 지정된 권한으로 실행되고 있지 않거나 전달되는 자격 증명이 유효하지 않은 경우 winform 앱이 실행 중이고 올바른 자격 증명을 제공하는 것처럼 보입니다. winforms 대 Windwos 서비스를 만들 때 Fiddler를 사용하여 요청을 검사하고 차이점을 확인하십시오.

+0

나는 내 Windows 서비스를 디버그하려고 시도했으며 서비스 클라이언트에 대한 연결을 열려고 시도 할 때 위의 오류를 발견했습니다. BTW는 Fiddler 무엇이며 net.tcp 바인딩이있는 WCF 서비스가있는 시나리오와 같은 상황에서 유용합니다. 알려주십시오 – Bravo

+0

WCF 서비스에 암시 적으로 보안을 구현하지 않았습니다. 기본 보안 구현 일 수 있습니다. – Bravo

+0

@Bravo : Fiddler는 네트워크를 통해 들어오고 나가는 트래픽을 검사하는 도구입니다. 위의 구성에서 서비스는 net.Tcp를 사용합니다. IIS 또는 자체 호스팅에서 호스팅되는 경우 알 수 있습니까? 또한 다른 컴퓨터에 Windows 서비스가 있습니까? – Rajesh

1

이 게시물에 대한 내 대답을 확인하십시오 The server has rejected the client credentials.

보안 노드에 유의하십시오.

<bindings> 
    <netTcpBinding> 
    <binding name="customTcpBinding" maxReceivedMessageSize="20480000" transferMode="Streamed" > 
     <security mode="None"></security> 
    </binding> 
    </netTcpBinding> 
</bindings> 
+1

이것은 나를 위해 일했다. –

관련 문제