2014-04-12 31 views
1

不行我的服务器上,运行在IIS 7中托管的Windows身份验证WCF应用:WCF Windows身份验证,本地调试好,但在服务器

IIS配置:Windows验证:禁用;匿名:启用

<system.serviceModel> 
    <services> 
     <service name="Services.AccountService" behaviorConfiguration="MyServiceTypeBehaviors"> 
     <endpoint address="" binding="ws2007HttpBinding" bindingConfiguration="AccountServiceBinding" 
     contract="Contracts.IAccountService" /> 
     </service> 
    </services> 
    <behaviors> 
     <serviceBehaviors> 
      <behavior name="MyServiceTypeBehaviors" > 
     <!--<serviceDebug includeExceptionDetailInFaults="true"/>--> 
       <serviceMetadata httpGetEnabled="true" httpGetUrl="" /> 
      </behavior> 
     </serviceBehaviors> 
    </behaviors> 
    <bindings> 
     <ws2007HttpBinding> 
      <binding name="AccountServiceBinding" > 
       <security mode="Message"> 
        <message clientCredentialType="Windows" /> 
       </security> 
      </binding> 
     </ws2007HttpBinding> 
    </bindings> 
</system.serviceModel> 

,然后创建一个MVC4应用程序使用下面的代码来调用WCF服务:

WS2007HttpBinding myBinding = new WS2007HttpBinding(); 
myBinding.Security.Mode = SecurityMode.Message; 
EndpointAddress endpoint = new EndpointAddress("http://server/accountservice.svc"); 

AccountServiceClient _client = new AccountServicesObjects.AccountServiceClient(myBinding, endpoint); 
_client.ClientCredentials.Windows.ClientCredential.UserName = "username"; 
_client.ClientCredentials.Windows.ClientCredential.Password = "password"; 

var user = _client.GetUserInformation(); // works fine 

后,我完成了这个mvc4应用程序,我部署此网站在同一台服务器这是运行WCF之一,当我登录时,发生:

System.ServiceModel.Security.SecurityNegotiationException: The caller was not authenticated by the service. 
System.ServiceModel.FaultException:The request for security token could not be satisfied because authentication failed. 
on System.ServiceModel.Security.SecurityUtils.ThrowIfNegotiationFault(Message message, EndpointAddress target) 
on System.ServiceModel.Security.SspiNegotiationTokenProvider.GetNextOutgoingMessageBody(Message incomingMessage, SspiNegotiationTokenProviderState sspiState) 

这是怎么发生的?

+0

为什么您在IIS上禁用Windows身份验证? – rene

回答

0

看来你的服务还没有开始。如果启用跟踪,您可以找到一个例外。有一个在你的配置错误 - 你没有基址,但已设置HttpGetUrl为true(该选项必须设置基址)

这应该为你工作:

<service name="Services.AccountService" behaviorConfiguration="MyServiceTypeBehaviors"> 
    <endpoint address="accountservice.svc" binding="ws2007HttpBinding" 
     bindingConfiguration="AccountServiceBinding" 
     contract="Services.IAccountService" /> 
    <host> 
      <baseAddresses> 
       <add baseAddress="http://localhost:8000/"/> 
      </baseAddresses> 
    </host> 
</service>