none
Авторизация клиента web-сервиса RRS feed

  • Общие обсуждения

  • Есть web-сервис с авторизацией Windows. Пишу простой клиент с авторизацией, делаю двумя способами.

    Первый, описанный в MSDN:

    testWebService.WebService serv = new WindowsFormsApplication.testWebService.WebService();
    
    CredentialCache credentialCache = new CredentialCache();
    credentialCache.Add(new Uri("http://10.12.4.84:555"), "Basic", new NetworkCredential("admin", "qwerty"));
    
    serv.PreAuthenticate = true;
    serv.UnsafeAuthenticatedConnectionSharing = true;
    serv.UseDefaultCredentials = false;
    serv.Credentials = credentialCache;
    MessageBox.Show(serv.HelloWorld());

    Получаю exception: "Сбой запроса с состоянием HTTP 401: Unauthorized."

    Есть второй способ:

    testWebService.WebService serv = new WindowsFormsApplication.testWebService.WebService();
    
    serv.PreAuthenticate = true;
    serv.Credentials = new NetworkCredential("admin", "qwerty");
    MessageBox.Show(serv.HelloWorld());

    Здесь ошибка не возникает, результат функции я получаю. Но, если посмотреть трасером запросы, то видно:

    >>
    POST /WebService.asmx HTTP/1.1
    User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; MS Web Services Client Protocol 2.0.50727.8669)
    VsDebuggerCausalityData: uIDPo4S43It5e8VGlFWEujJ0PwQAAAAAx/lcDRXTvEuToGjaJgfXNvtbEZCX8cpMmg+kYz9tEMQACQAA
    Content-Type: text/xml; charset=utf-8
    SOAPAction: "http://tempuri.org/HelloWorld"
    Host: 10.12.4.84:555
    Content-Length: 288
    Expect: 100-continue
    Connection: Keep-Alive

    <<
    HTTP/1.1 401 Unauthorized
    Content-Length: 1777
    Content-Type: text/html
    Server: Microsoft-IIS/6.0
    WWW-Authenticate: Negotiate
    WWW-Authenticate: NTLM
    X-Powered-By: ASP.NET
    Date: Sun, 22 Nov 2015 21:31:17 GMT

    >>
    POST /WebService.asmx HTTP/1.1
    User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; MS Web Services Client Protocol 2.0.50727.8669)
    VsDebuggerCausalityData: uIDPo4S43It5e8VGlFWEujJ0PwQAAAAAx/lcDRXTvEuToGjaJgfXNvtbEZCX8cpMmg+kYz9tEMQACQAA
    Content-Type: text/xml; charset=utf-8
    SOAPAction: "http://tempuri.org/HelloWorld"
    Authorization: Negotiate TlRMTVNTUAABAAAAt4II4gAAAAAAAAAAAAAAAAAAAAAKAAAoAAAADw==
    Host: 10.12.4.84:555
    Content-Length: 0

    <<
    HTTP/1.1 401 Unauthorized
    Content-Length: 1661
    Content-Type: text/html
    Server: Microsoft-IIS/6.0
    WWW-Authenticate: Negotiate TlRMTVNTUAACAAAAHgAeADgAAAA1goriyVZLH+T8M7UAAAAAAAAAAIwAjABWAAAABQLODgAAAA9JAEIAVAAtAEYARQBSAE8AWABTAEUAUgBWAEUAUgACAB4ASQBCAFQALQBGAEUAUgBPAFgAUwBFAFIAVgBFAFIAAQAeAEkAQgBUAC0ARgBFAFIATwBYAFMARQBSAFYARQBSAAQAHgBpAGIAdAAtAGYAZQByAG8AeABzAGUAcgB2AGUAcgADAB4AaQBiAHQALQBmAGUAcgBvAHgAcwBlAHIAdgBlAHIAAAAAAA==
    X-Powered-By: ASP.NET
    Date: Sun, 22 Nov 2015 21:31:22 GMT


    >>
    POST /WebService.asmx HTTP/1.1
    User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; MS Web Services Client Protocol 2.0.50727.8669)
    VsDebuggerCausalityData: uIDPo4S43It5e8VGlFWEujJ0PwQAAAAAx/lcDRXTvEuToGjaJgfXNvtbEZCX8cpMmg+kYz9tEMQACQAA
    Content-Type: text/xml; charset=utf-8
    SOAPAction: "http://tempuri.org/HelloWorld"
    Authorization: Negotiate TlRMTVNTUAADAAAAGAAYAIoAAAAmASYBogAAAAAAAABYAAAAGgAaAFgAAAAYABgAcgAAABAAEADIAQAANYKI4goAACgAAAAP8hXI5f7TU32hFznSeSVVIBAENAQ8BDgEPQQ4BEEEQgRABDAEQgQ+BEAESwBUAFkAVQBSAE0ATwBSAEUAWgBPAFYAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAADd1YwEABq3BTUet+GiOG9wEBAAAAAAAA0CU2FW0l0QFNLgct4FUs9gAAAAACAB4ASQBCAFQALQBGAEUAUgBPAFgAUwBFAFIAVgBFAFIAAQAeAEkAQgBUAC0ARgBFAFIATwBYAFMARQBSAFYARQBSAAQAHgBpAGIAdAAtAGYAZQByAG8AeABzAGUAcgB2AGUAcgADAB4AaQBiAHQALQBmAGUAcgBvAHgAcwBlAHIAdgBlAHIACAAwADAAAAAAAAAAAAAAAAAwAAC1Fv/hK7JdehwagKQYp5Ls+mrLKQw7oTuhkVpOVahb+goAEAAAAAAAAAAAAAAAAAAAAAAACQAeAEgAVABUAFAALwAxADAALgAxADIALgA0AC4AOAA0AAAAAAAAAAAAbH1eUTDrdvLCD92+c1IWcA==
    Host: 10.12.4.84:555
    Content-Length: 288
    Expect: 100-continue


    [23.11.2015 0:31:00:803]
    HTTP/1.1 100 Continue

    Т.е. видно, что авторизация не с первого запроса проходит. И так всегда. Тоже самое происходит и в другом проекте, где подобная авторизация - всегда авторизация проходит на втором запросе только. Почему так?

    22 ноября 2015 г. 21:40