Sono relativamente nuovo a WCF ma ho un servizio WCF ospitato in IIS che ha diverse query sul nostro server SQL. Sto consumando il servizio WCF con un'applicazione WPF. Quello che sto cercando di fare è consentire all'autenticazione di Windows di passare dal client WPF, al servizio WCF, al server SQL in modo che le query SQL vengano eseguite come utente dei client. Ho cercato di configurare il sito web e l'host in vari modi senza fortuna fino ad ora.Servizio WCF ospitato da IIS e query SQL che utilizzano l'autenticazione di Windows
Sul mio sito Web del servizio WCF, ho autenticazione anonima = true (per MEX), rappresentazione ASP.NET = true e autenticazione di Windows = true.
Nel mio servizio 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="data source=MYSERVER;initial catalog=ADATracking;integrated security=True;multipleactiveresultsets=True;App=EntityFramework"" providerName="System.Data.EntityClient" />
</connectionStrings>
</configuration>
Poi nel mio client WPF app.config ho:
<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>
Le mie chiamate di servizio sono solo tornando query semplici da SQL che utilizza i metadati per consentire la rappresentazione. Ogni volta che eseguo il client e chiamo qualcosa dal mio servizio sto ricevendo un errore aprendo la connessione dati per "NT Authority/ANONYMOUS LOGIN" anche con AnonymousAuthentication = false set in IIS ??? Qualsiasi aiuto sarebbe molto apprezzato. Grazie!
[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();
}
}
}
Eccezionale! Sono contento che tu abbia funzionato. – CodeWarrior