简体   繁体   中英

Windows Authentication for WCF service with Silverlight 5, IIS 7.5

I have a Silverlight 5 Prism application with a (regular) WCF service in an ASP.net project. I'm using IIS 7.5 to host it on the localhost. I followed all the steps in

How to: Use Windows Authentication to Secure a Service for Silverlight Applications

How to: Host a Secure Service in ASP.NET for Silverlight Applications

but I can't get windows authentication to work. Whenever I turn off anonymous authentication in IIS, my application throws an The remote server returned an error: NotFound. exception because it doesn't find the WCF service.

When I try to update the service reference in Visual Studio I get the error Security settings for this service require 'Anonymous' Authentication but it is not enabled for the IIS application that hosts this service.

When I turn on Anonymous Authentication the service works, but I don't get the windows user credentials. My browser (IE 8) is set to use integrated windows authentication and automatically logon in the local intranet.

What am I doing wrong?

Here is my IIS 7.5 configuration. The Application pool is running in Integrated mode:

IIS配置

web.config:

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
  <system.web>
    <compilation debug="true" />
    <authentication mode="Windows" />
  </system.web>
  <system.serviceModel>
  <behaviors>
    <serviceBehaviors>
      <behavior name="">
        <serviceMetadata httpGetEnabled="true" />
        <serviceDebug includeExceptionDetailInFaults="false" />
       </behavior>
      </serviceBehaviors>
    </behaviors>
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true" />  
  </system.serviceModel>
</configuration>

ServiceReferences.ClientConfig:

<configuration>
    <system.serviceModel>
        <bindings>
            <basicHttpBinding>
                <binding name="BasicHttpBinding_ISecurityService" maxBufferSize="2147483647"
                    maxReceivedMessageSize="2147483647">
                    <security mode="TransportCredentialOnly" />
                </binding>
            </basicHttpBinding>
        </bindings>
        <client>
            <endpoint address="http://localhost:85/SecurityService/SecurityService.svc"
                binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_ISecurityService"
                contract="SecurityServiceReference.ISecurityService" name="BasicHttpBinding_ISecurityService" />
        </client>
    </system.serviceModel>
</configuration>

I am only guessing on the WCF part that this may not be set up properly for windows authentication. The wcf service needs to be configured to authenticate the requests from IIS with windows credentials as well. So, in that case, I would expect that there needs to be a behavior in the service demanding this. Check to see if you have configured these correcntly. servicecredentials and clientcredentials.

serviceCredentials

Security behaviours in WCF

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM