2012-01-23 18 views
6

私はWCFの新機能を使用していますが、SQL Serverにいくつかのクエリを持つIISでホストされているWCFサービスがあります。私はWPFアプリケーションでWCFサービスを利用しています。私がやろうとしているのは、Windows認証がWPFクライアントからWCFサービスに、SQL Serverに渡され、SQLクエリがクライアントユーザーとして実行されるようにすることです。私はこれまでウェブサイトやホストをさまざまな形で設定しようとしてきました。IISでホストされているWindows認証を使用したWCFサービスとSQLクエリ

私のWCFサービスのWebサイトでは、匿名認証=真(MEXの場合)、ASP.NET偽装=真、Windows認証=真を持っています。私のWCFサービスのWeb.configで

<configuration> 
    <system.web> 
    <customErrors mode="Off"/> 
    <authentication mode="Windows"/> 
    <compilation debug="true" targetFramework="4.0"> 
     <assemblies> 
     <add assembly="System.Data.Entity, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" /> 
     </assemblies> 
    </compilation> 
    </system.web> 
    <system.serviceModel> 
    <bindings> 
     <wsHttpBinding> 
     <binding maxReceivedMessageSize="5000000" name="WindowsSecurity"> 
      <readerQuotas maxDepth="200"/> 
      <security mode="Transport"> 
      <transport clientCredentialType="Windows" /> 
      </security> 
     </binding> 
     </wsHttpBinding> 
    </bindings> 
    <services> 
     <service name="ADATrackingService" behaviorConfiguration="ServiceBehavior"> 
     <endpoint address="" binding="wsHttpBinding" bindingConfiguration="WindowsSecurity" 
      name="wsHttpEndpoint" contract="IADATrackingService" /> 
     <endpoint address="mex" binding="mexHttpsBinding" name="MexHttpsBindingEndpoint" 
      contract="IMetadataExchange" /> 
     </service> 
    </services> 
    <behaviors> 
     <serviceBehaviors> 
     <behavior name="ServiceBehavior"> 
      <serviceMetadata httpGetEnabled="false" httpsGetEnabled="true" /> 
      <serviceDebug includeExceptionDetailInFaults="true" /> 
      <serviceAuthorization impersonateCallerForAllOperations="true" /> 
     </behavior> 
     </serviceBehaviors> 
    </behaviors> 
    <serviceHostingEnvironment multipleSiteBindingsEnabled="true" /> 
    </system.serviceModel> 
    <system.webServer> 
    <modules runAllManagedModulesForAllRequests="true" /> 
    </system.webServer> 
    <connectionStrings> 
    <add name="ADATrackingEntities" connectionString="metadata=res://*/EntityModel.ADATrackingModel.csdl|res://*/EntityModel.ADATrackingModel.ssdl|res://*/EntityModel.ADATrackingModel.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=MYSERVER;initial catalog=ADATracking;integrated security=True;multipleactiveresultsets=True;App=EntityFramework&quot;" providerName="System.Data.EntityClient" /> 
    </connectionStrings> 
</configuration> 

はその後、私のWPFクライアントApp.configファイルに私が持っている:

<configuration> 
    <system.serviceModel> 
     <behaviors> 
     <endpointBehaviors> 
      <behavior name="WindowsAuthentication"> 
      <clientCredentials> 
       <windows allowedImpersonationLevel="Delegation"/> 
      </clientCredentials> 
      </behavior> 
     </endpointBehaviors> 
     </behaviors> 
     <bindings> 
      <wsHttpBinding> 
       <binding name="wsHttpEndpoint" closeTimeout="00:01:00" openTimeout="00:01:00" 
        receiveTimeout="00:10:00" sendTimeout="00:01:00" bypassProxyOnLocal="false" 
        transactionFlow="false" hostNameComparisonMode="StrongWildcard" 
        maxBufferPoolSize="524288" maxReceivedMessageSize="5000000" 
        messageEncoding="Text" textEncoding="utf-8" useDefaultWebProxy="true" 
        allowCookies="false"> 
        <readerQuotas maxDepth="200" maxStringContentLength="8192" maxArrayLength="16384" 
         maxBytesPerRead="4096" maxNameTableCharCount="16384" /> 
        <reliableSession ordered="true" inactivityTimeout="00:10:00" 
         enabled="false" /> 
        <security mode="Transport"> 
         <transport clientCredentialType="Windows" proxyCredentialType="None" 
          realm="" /> 
         <message clientCredentialType="Windows" negotiateServiceCredential="true" /> 
        </security> 
       </binding> 
      </wsHttpBinding> 
     </bindings> 
     <client> 
      <endpoint address="https://MyService.svc" 
       binding="wsHttpBinding" behaviorConfiguration="WindowsAuthentication" bindingConfiguration="wsHttpEndpoint" 
       contract="ADATrackingService.IADATrackingService" name="wsHttpEndpoint"> 
       <identity> 
        <servicePrincipalName value="host/MyServer.com" /> 
       </identity> 
      </endpoint> 
     </client> 
    </system.serviceModel> 
</configuration> 

マイサービスコールだけから単純なクエリを戻ってきています偽装を許可するためのメタデータを使用したSQL。クライアントを実行してサービスから何かを呼び出すたびに、IISでAnonymousAuthentication = falseが設定されていても、「NT Authority/ANONYMOUS LOGIN」のデータ接続を開くときにエラーが表示されるだけです。どんな助けでも大歓迎です。ありがとう!

[OperationBehavior(Impersonation = ImpersonationOption.Required)] 
public List<IndividualDisability> GetIndividualDisabilities() 
{ 
    WindowsIdentity callerWindowsIdentity = ServiceSecurityContext.Current.WindowsIdentity; 
    if (callerWindowsIdentity == null) 
    { 
     throw new InvalidOperationException 
     ("The caller cannot be mapped to a Windows identity."); 
    } 
    using (callerWindowsIdentity.Impersonate()) 
    { 
     using (var context = new ADATrackingEntities()) 
     { 
      return context.IndividualDisabilities.OfType<IndividualDisability>().Include("ADACode").Include("Individual").Include("Disability").ToList(); 
     } 
    } 
} 

答えて

5

まあ、いくつかの周りを閲覧した後、今日はもっと。私はついにそれを働かせました!問題は、アクティブディレクトリでは、SQL Serverのボックスに委任を許可する必要があったということでした。 ADには、Webサーバーボックスにポート1433のSQlサーバーボックスのSQlサービスに委任できるように設定する必要がある設定があります。また、Webサーバーでkerebos認証用にセットアップされていることを確認しなければなりませんでした。このブログ記事は、まさに私の状況を説明し、私は最初から最後まで作業それを得る助けた:返信用

ASP.Net Impersonation

+0

優秀!あなたがうまく働いてうれしい。 – CodeWarrior

0

IISでは、明示的に匿名認証を削除しましたか?次の操作を実行します。

  1. IISマネージャを開きます。
  2. WCFサービスアプリケーションに移動します。
  3. [機能]ビューで、[IIS]の[認証]をクリックします。
  4. Windows認証を除くすべての認証方式を削除します。

WPFアプリケーションが干渉しないようにするには、最初にwcftestclientでテストします。

  1. オープン開発者コマンドウィンドウ([メニュー]> [プログラム]> [MicrosoftのVisual Studio 2010> Visual Studioツール>のVisual Studioコマンドプロンプト(2010)を起動します)
  2. wcftestclient https://url.to/myservice.svc
+0

感謝を。私は、IISとサービスですべての設定が正しく行われていると思います。 WCFテストクライアントを実行しているときに、「必要な偽装レベルが提供されていないか、提供された偽装レベルが無効です」というエラーが表示されます。 – ccorrin

+0

ああ!あなたはちょうどそれの地獄のためにあなたの偽装をハードコーディングしようとしましたか?ウェブに以下を追加してください。あなたが良いことを確認するには、サービスからSQLサーバーへの接続を確認する必要があります。 CodeWarrior

+0

値をハードコーディングしてもエラーが発生しますweb.configにあります。 "ログインがNT権限/匿名ログインでSQLに失敗しました"。私は私のSQLボックスで設定する必要があるかもしれないと思っているのですか? – ccorrin

関連する問題