我有一个托管在 IIS 中的 WCF 服务,启用了集成的 Windows 身份验证并禁用了匿名身份验证。当我尝试从 ASP.NET 调用此服务时,我收到以下 MessageSecurityException:
“HTTP 请求未经客户端身份验证方案‘协商’未经授权。从服务器收到的身份验证标头为‘协商,NTLM’。]”
有任何想法吗?
这是我的服务配置:
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="CalculatorServiceBasicHttpBinding">
<security mode="TransportCredentialOnly">
<transport clientCredentialType="Windows" />
</security>
</binding>
</basicHttpBinding>
</bindings>
<services>
<service name="Service.CalculatorService"
behaviorConfiguration="CalculatorServiceBehavior">
<endpoint name="BasicHttpEndpoint"
address=""
binding="basicHttpBinding"
bindingConfiguration="CalculatorServiceBasicHttpBinding"
contract="Framework.ICalculatorService">
</endpoint>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="CalculatorServiceBehavior">
<serviceMetadata httpGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="true"/>
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
</system.serviceModel>
这就是我调用服务的方式:
var basicHttpBinding = new BasicHttpBinding();
basicHttpBinding.Security.Mode = BasicHttpSecurityMode.TransportCredentialOnly;
basicHttpBinding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Windows;
var factory = new ChannelFactory<Framework.ICalculatorService>(basicHttpBinding, new EndpointAddress("http://localhost/CalculatorService/CalculatorService.svc"));
factory.Credentials.Windows.ClientCredential = CredentialCache.DefaultNetworkCredentials;
var proxy = factory.CreateChannel();
var emailAddress = proxy.GetMyEmailAddress();
((ICommunicationObject)proxy).Close();
factory.Close();