1
votes

On my Server, running a Windows Authentication WCF application hosted in IIS 7:

IIS Config: Windows Auth : disabled; anonymous: enabled

<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>

and then I create a MVC4 Application with following code to call WCF service:

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

After I finished this mvc4 application, I deploy this website to the Same server which is running WCF one, when I login, occurs:

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)

how this happend?

1
Why did you disable windows authentication on IIS?rene

1 Answers

0
votes

It seems your service hasn't been started at all. If you enable tracing you can find an exception. There is an error in your configuration - you have no base address, but you have set HttpGetUrl to true (for that option you have to set base address)

This should work for you:

<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>