简体   繁体   中英

Calling a WCF service using Windows Auth from a Windows Store App

I have a WCF service deployed to IIS on my local machine configured for Win Auth

<basicHttpBinding>
    <binding name="NewBinding0">
      <security mode="TransportCredentialOnly">
        <transport clientCredentialType="Windows" />
      </security>
    </binding>
  </basicHttpBinding>

I have a test WPF project that call it which works just fine. I tried to create a Windows Store app and use my logged on (domain) user to call the service but can't get this to work My user is a domain user and I can see it by calling Windows.System.UserProfile.UserInformation.GetDomainNameAsync()

If I implement the partial ConfigureEndpoint and set the credentials explicitly I can get to the service just fine -

        static partial void ConfigureEndpoint(System.ServiceModel.Description.ServiceEndpoint serviceEndpoint, System.ServiceModel.Description.ClientCredentials clientCredentials)
    {
        clientCredentials.Windows.ClientCredential = new System.Net.NetworkCredential("<domain>\\<username>", "<password>");
    }

but if I simply put

clientCredentials.Windows.AllowedImpersonationLevel = System.Security.Principal.TokenImpersonationLevel.Impersonation;

I get the following error

{"The HTTP request is unauthorized with client authentication scheme 'Ntlm'. The authentication header received from the server was 'Negotiate,NTLM'."}

I have configured the Enterprise Authentication and Private Networks (Client & Server) capabilities

What do I need to do to call the service in the context of the logged on domain user?

(I've found this unanswered question which probably refers to the same issue, but no answer yet?

Turns out that the issue was a result of me hosting the service (for testing) on my laptop and calling it using 'localhost'.

I've deployed the same service to another server on our domain and updated the endpoint address in the app and it all worked just fine.

Looks like there's a restriction on windows store app calling services on localhost

Not quite sure why this is working fine if I provide the credentials explicitly and does not if I just carry the logged on user though..

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM