我有一個WCF服務託管在IIS中,啓用了集成的Windows身份驗證並禁用了匿名身份驗證。當我嘗試從ASP.NET調用此服務時,出現以下MessageSecurityException:將Windows身份傳遞給WCF從ASP.NET
「HTTP請求未經授權,客戶端身份驗證方案'Negotiate'。從服務器收到的身份驗證頭是'Negotiate,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();
謝謝。我在IIS 5.1(運行XP)上本地託管ASP.NET客戶端,並決定將其移動到運行IIS 6的服務器上並工作。應該知道。我認爲這並不重要,但很高興知道它爲什麼不起作用。5.任何想法? – Yaron 2012-01-06 09:56:35
對不起,幾年前從我的短期記憶中已經清除了IIS 5的知識:) – 2012-01-06 11:58:52