2012-01-23 32 views
6

Jestem całkiem nowy w WCF, ale mam usługę WCF hostowaną w IIS, która ma kilka zapytań do naszego serwera SQL. Używam usługi WCF z aplikacją WPF. Próbuję zezwolić na uwierzytelnianie systemu Windows od klienta WPF, do usługi WCF, do serwera SQL, aby zapytania SQL były wykonywane jako klienty. Próbowałem skonfigurować stronę internetową i hosta na różne sposoby, bez powodzenia.Usługi hostowane w usługach IIS i zapytania SQL za pomocą uwierzytelniania systemu Windows przy użyciu uwierzytelniania Windows

Na mojej stronie usługi WCF Service, mam anonimowe uwierzytelnianie = true (dla MEX), ASP.NET Impersonation = true i Windows Authentication = true.

W moim usługi 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> 

Wtedy w moim klientem WPF app.config mam:

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

moje telefony serwisowe są po prostu powrocie prostych zapytań od SQL używający metadanych w celu umożliwienia podszywania się. Za każdym razem, gdy uruchamiam klienta i wywołuję coś z mojej usługi, właśnie dostaję błąd podczas otwierania połączenia danych dla "NT Authority/ANONYMOUS LOGIN" nawet przy AnonymousAuthentication = false set w IIS ??? Każda pomoc będzie bardzo ceniona. Dzięki!

[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(); 
     } 
    } 
} 

Odpowiedz

5

Cóż, po przeglądanie wokół niektórych więcej dzisiaj. W końcu udało mi się to zrobić! Problem polegał na tym, że w aktywnym katalogu musiałem zezwolić na delegowanie do serwera SQL Server. W AD jest ustawienie, które musisz ustawić na skrzynce serwera WWW, aby umożliwić mu delegowanie do Usługi SQl na twoim serwerze SQl na porcie 1433. Musiałem również upewnić się, że został skonfigurowany do uwierzytelniania kerebos na serwerze internetowym. Ten blogu wyjaśnić moją sytuację dokładnie i pomógł mi dostać pracy od początku do końca:

ASP.Net Impersonation

+0

Znakomity! Cieszę się, że to działa. – CodeWarrior

0

Czy w IIS jawnie usunięto anonimowe uwierzytelnianie? Wykonaj następujące czynności:

  1. Otwórz Menedżera usług IIS.
  2. Przejdź do aplikacji usługi WCF.
  3. W widoku Funkcje w obszarze IIS kliknij opcję Uwierzytelnianie.
  4. Usunięcie dowolnego schematu uwierzytelniania z wyjątkiem uwierzytelniania systemu Windows. (Anonim jest domyślnie włączony.)

Aby upewnić się, że aplikacja WPF w żaden sposób nie ingeruje, najpierw należy przetestować z wcftestclient.

  1. Otwórz Deweloperzy Okno poleceń (Menu Start> Programy> Microsoft Visual Studio 2010> Visual Studio Tools> wizualna Prompt Studio Command (2010))
  2. wcftestclient https://url.to/myservice.svc
+0

Dzięki za odpowiedź. Myślę, że mam wszystko poprawnie skonfigurowane w IIS i usługi. Po uruchomieniu z klientem testowym WCF im teraz pojawia się błąd: "Nie podano wymaganego poziomu personifikacji lub podany poziom personifikacji jest nieprawidłowy." – ccorrin

+0

Ah ha! Czy próbowaliście ciężko kodować swoje podszywanie się tylko po to? Dodaj następujące elementy do internetu.config, aby upewnić się, że od usługi do serwera SQL jesteś dobry: CodeWarrior

+0

Otrzymuję błąd, nawet gdy kodowanie wartości jest trudne w pliku web.config. "Logowanie nie powiodło się w SQL dla NT Authority/Anonymous Login". Myślę, że może być coś, co muszę skonfigurować na moim polu SQL? – ccorrin

Powiązane problemy