WCF Windows authentication issue with REST service

拈花ヽ惹草 提交于 2019-12-11 02:49:57

问题


I'm having some difficulty setting up a WCF service to run under Windows authentication. The service is only consumed via jQuery using ajax.

IIS (version 6 on server 2003) is set to only allow Windows Authentication.

web.config has the <authentication mode="Windows" /> tag.

Here's the service section of the web.config:

<system.serviceModel>
<behaviors>
  <endpointBehaviors>
    <behavior name="AspNetAjaxBehavior">
        <webHttp />
    </behavior>
  </endpointBehaviors>
    <serviceBehaviors>
        <behavior name="ServiceBehavior">
            <serviceMetadata httpGetEnabled="true"/>
        </behavior>
    </serviceBehaviors>
</behaviors>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true"/>
<services>
    <service name="SearchService" behaviorConfiguration="ServiceBehavior">
        <endpoint address="http://localhost:9534/SearchService.svc" behaviorConfiguration="AspNetAjaxBehavior"
            binding="webHttpBinding" bindingConfiguration="webWinBinding"
            name="searchServiceEndpoint" contract="MyApp.Services.ISearchService">
        </endpoint>
    </service>
</services>
<bindings>
    <webHttpBinding>
        <binding name="webWinBinding" maxBufferSize="2147483647" maxReceivedMessageSize="2147483647">
            <security mode="TransportCredentialOnly">
                <transport clientCredentialType="Windows"/>
            </security>
            <readerQuotas maxArrayLength="100000" maxStringContentLength="2147483647" />
        </binding>
    </webHttpBinding>
</bindings>

The interface looks like this:

[ServiceContract(Namespace = "http://MyService.ServiceContracts/2012/02", Name = "SearchService")]
public interface ISearchService
{
    [WebGet(ResponseFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.Bare, UriTemplate = "GetSomeData?filter={filter}")]
    [OperationContractAttribute(Action = "GetSomeData")]
    string GetSomeData(string filter);
}

And the implementation:

[ServiceBehavior(IncludeExceptionDetailInFaults = true)]
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Required)]
public class SearchService : ISearchService
{
    public string GetSomeData(string filter)
    {
        // Call Database and get some results
        // return the results
        return "";
    }
}

When I navigate to the service in Internet Explorer, it prompts me for my username and password, despite having Windows Authentication turned on.

As soon as I enable Anonymous Authentication, the service loads just fine and everything works. Problem is, I have other things going on in the web application that require anonymous to be turned off.

I've scoured the web and can't find anything on this problem.

来源:https://stackoverflow.com/questions/9134433/wcf-windows-authentication-issue-with-rest-service

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!