2014-04-12 57 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>