none
web services with Windows store app error

    Question

  • I am calling WCF service method from windows store application but it gives this error:

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

    can u help me on How I can fix it? 

    Thanks.

    Friday, October 19, 2012 8:50 PM

Answers

  • See this sample:

     var handler = new HttpClientHandler
                       {UseDefaultCredentials = false, Credentials = new NetworkCredential("user", "pass")};
    
    var httpClient = new HttpClient(handler); 
    
    var values = new Dictionary<string, string> { { "username", "hsdhdh@jkdd.com" }, { "password", "6564" } };
     //Header of the http request
    HttpContent header = new FormUrlEncodedContent(values);
    var response = await httpClient.PostAsync(urlStringValue, header);
    response.EnsureSuccessStatusCode();

    See this:


    Sara Silva

    • Marked as answer by JORDAN RTG Monday, October 22, 2012 9:15 PM
    Friday, October 19, 2012 8:58 PM
  • I solved the problem by converting the security scheme to NTLM or Windows instead of anonymous security (the windows store app use anonymous security configuration when adding service reference thru Add service reference wizard), the trick part here is where to specify the new configuration because the Windows store app does not has App.cpnfig or Web.config files, you can specify the security configuration using the code in the Reference.cs file under the service itself. or you can specify it by implementing the same partial class outside this file. (so it stay there even if u update the reference) .

    thanks all.

    • Marked as answer by JORDAN RTG Monday, October 22, 2012 9:15 PM
    Monday, October 22, 2012 9:14 PM

All replies

  • See this sample:

     var handler = new HttpClientHandler
                       {UseDefaultCredentials = false, Credentials = new NetworkCredential("user", "pass")};
    
    var httpClient = new HttpClient(handler); 
    
    var values = new Dictionary<string, string> { { "username", "hsdhdh@jkdd.com" }, { "password", "6564" } };
     //Header of the http request
    HttpContent header = new FormUrlEncodedContent(values);
    var response = await httpClient.PostAsync(urlStringValue, header);
    response.EnsureSuccessStatusCode();

    See this:


    Sara Silva

    • Marked as answer by JORDAN RTG Monday, October 22, 2012 9:15 PM
    Friday, October 19, 2012 8:58 PM
  • thanks,

    what is the urlStringValue?

    I tried the other links but it doesn't work :(

    Monday, October 22, 2012 1:22 PM
  • Is the string with the value of the url

    Sara Silva
    My Windows 8 Store Apps Samples
    Follow me in Twitter @saramgsilva
    (If my reply answers your question, please propose it as an answer because it will help other users)

    Monday, October 22, 2012 1:34 PM
  • I tried your example, but it still gives the same error.

    For the other links, the problem I don't know how to convert the security configuration from anonymous to NTLM, because the windows store app doesn't generate app.config file, the configuration should changed within the code itself !!

    Thanks.

    Monday, October 22, 2012 2:34 PM
  • using wcf service right?

    client.ClientCredentials.Windows.ClientCredential = new NetworkCredentials("username", "password") client.ClientCredentials.Windows.AllowedImpersonationLevel = System.Security.Principal.TokenImpersonationLevel.Impersonation;


    client is the serviceclient proxy


    Monday, October 22, 2012 2:52 PM
  • I solved the problem by converting the security scheme to NTLM or Windows instead of anonymous security (the windows store app use anonymous security configuration when adding service reference thru Add service reference wizard), the trick part here is where to specify the new configuration because the Windows store app does not has App.cpnfig or Web.config files, you can specify the security configuration using the code in the Reference.cs file under the service itself. or you can specify it by implementing the same partial class outside this file. (so it stay there even if u update the reference) .

    thanks all.

    • Marked as answer by JORDAN RTG Monday, October 22, 2012 9:15 PM
    Monday, October 22, 2012 9:14 PM