2012-01-09 123 views
8

Windowsフォームサービスで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結合、文字列ターゲット名、のProtectionLevel requiredProtectionLevel、TokenImpersonationLevel allowedImpersonationLevel)
System.Net.Security.NegotiateStream.AuthenticateAsClient(NetworkCredentialの 資格、文字列ターゲット名に、プロテクトしたがって、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

ありがとうございました。私はいくつかの研究と試行錯誤メソッドの数日後に答えを得た:)よく私は私が答えを投稿するのが遅いと知っているが、私はその決して遅くないより良いと思う。

だからここ

<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> 

これが必要で、人を助ける希望:)

だから、KEYは、クライアントとサーバーの設定ファイルの上に同じ<security>タグを作ることです。

4

基本的に何が起こっているかのWinFormsから呼び出すときに持っているだろうのようなあなたの電話サービスは、適切な資格を持っていないことです。必要なのは偽装です。それはセットアップの少しを取ると、迷惑なのですが、それは動作します。

幸いにも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

を確認してください。偽装する相手を実際に教えてください。フラグを設定して魔法のように偽装することはできません。 2番目のリンクにある資料を読んでください。 –

1

WCFサービスで使用している認証モードは何ですか。 Windowsサービスが指定された権限で実行されていないか、渡された資格情報が有効でないときに、winformアプリケーションが実行されて正しい資格情報を提供しているようです。 winforms vs 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

これは私のために働いた –

関連する問題