仅在特定机器上调用Web Service时,c# – 401

我们已经开发了一个带有C#的WPF应用程序,并使用RestSharp与一个简单的Web Service进行通信,如下所示:

Client = new RestClient(serviceUri.AbsoluteUri);
Client.Authenticator = new NtlmAuthenticator(SvcUserName, SvcPassword.GetString());

这一切都很好,直到我们收到一些机器(大部分工作)的应用程序无法连接到该服务的电话.
直接致电与fiddler的服务方式工作.然后我们提取了一个小的.net控制台应用程序,并尝试使用RestSharp进行的服务调用,并直接使用HttpWebRequest,并且它再次与401失败.
现在我们启用了System.Net跟踪并注意到了一些事情.第一个401,这是正常的,故障机器生成这个日志:

System.Net Information: 0 : [4480] Connection#3741682 – Received headers
{
Connection: Keep-Alive
Content-Length: 1293
Content-Type: text/html
Date: Mon, 10 Aug 2015 12:37:49 GMT
Server: Microsoft-IIS/8.0
WWW-Authenticate: Negotiate,NTLM
X-Powered-By: ASP.NET
}.
System.Net Information: 0 : [4480] ConnectStream#39451090::ConnectStream(Buffered 1293 bytes.)
System.Net Information: 0 : [4480] Associating HttpWebRequest#2383799 with ConnectStream#39451090
System.Net Information: 0 : [4480] Associating HttpWebRequest#2383799 with HttpWebResponse#19515494
System.Net Information: 0 : [4480] Enumerating security packages:
System.Net Information: 0 : [4480] Negotiate
System.Net Information: 0 : [4480] NegoExtender
System.Net Information: 0 : [4480] Kerberos
System.Net Information: 0 : [4480] NTLM
System.Net Information: 0 : [4480] Schannel
System.Net Information: 0 : [4480] Microsoft Unified Security Protocol Provider
System.Net Information: 0 : [4480] WDigest
System.Net Information: 0 : [4480] TSSSP
System.Net Information: 0 : [4480] pku2u
System.Net Information: 0 : [4480] CREDSSP

System.Net Information: 0 : [4480] AcquireCredentialsHandle(package =
NTLM, intent = Outbound, authdata =
(string.empty)\corp\svc_account)

System.Net Information: 0 : [4480]
InitializeSecurityContext(credential =
System.Net.SafeFreeCredential_SECURITY, context = (null), targetName =
HTTP/mysvc.mycorp.com, inFlags = Delegate, MutualAuth,
Connection) System.Net Information: 0 : [4480]
InitializeSecurityContext(In-Buffers count=1, Out-Buffer length=40,
returned code=ContinueNeeded).

一台工作机器产生这个输出:

System.Net Information: 0 : [3432] Connection#57733168 – Empfangene Statusleiste: Version = 1.1, StatusCode = 401, StatusDescription = Unauthorized.
System.Net Information: 0 : [3432] Connection#57733168 – Header
{
Content-Type: text/html
Server: Microsoft-IIS/8.0
WWW-Authenticate: Negotiate,NTLM
X-Powered-By: ASP.NET
Date: Mon, 10 Aug 2015 15:15:11 GMT
Content-Length: 1293
} wurden empfangen.
System.Net Information: 0 : [3432] ConnectStream#35016340::ConnectStream(Es wurden 1293 Bytes gepuffert.)
System.Net Information: 0 : [3432] Associating HttpWebRequest#64062224 with ConnectStream#35016340
System.Net Information: 0 : [3432] Associating HttpWebRequest#64062224 with HttpWebResponse#64254500
System.Net Information: 0 : [3432] Sicherheitspakete werden enumeriert:
System.Net Information: 0 : [3432] Negotiate
System.Net Information: 0 : [3432] NegoExtender
System.Net Information: 0 : [3432] Kerberos
System.Net Information: 0 : [3432] NTLM
System.Net Information: 0 : [3432] Schannel
System.Net Information: 0 : [3432] Microsoft Unified Security Protocol Provider
System.Net Information: 0 : [3432] WDigest
System.Net Information: 0 : [3432] TSSSP
System.Net Information: 0 : [3432] pku2u
System.Net Information: 0 : [3432] CREDSSP

System.Net Information: 0 : [3432] AcquireCredentialsHandle(package =
Negotiate, intent = Outbound, authdata =
System.Net.SafeSspiAuthDataHandle) System.Net Information: 0 : [3432]
InitializeSecurityContext(credential =
System.Net.SafeFreeCredential_SECURITY, context = (null), targetName =
HTTP/mysvc.mycorp.com, inFlags = Delegate, MutualAuth, Connection)

System.Net Information: 0 : [3432] InitializeSecurityContext(Anzahl
von In-Buffers = 1, Länge von Out-Buffer = 40, zurückgegebener Code =
ContinueNeeded).

我想知道错误机器上的某些配置是否会导致这种情况.目前我不知道下一步要去哪里.

更新:
以下是我们简单测试工具的代码:

RestClient Client = new RestClient("https://mysvc.mycorp.com/service.svc");
        Client.Authenticator = new NtlmAuthenticator("corp\\svc_account", "mypassword");
        var request = new RestRequest("api/Method", Method.POST);
        request.RequestFormat = DataFormat.Json;
        request.AddBody(new { Device_Key = "somestring" });
        request.Timeout = 200000;


        RestResponse response = (RestResponse)Client.Execute(request);

更新2:
我们现在已经确认,这个问题只发生在新安装的win 7机器上,这些机器具有更新的企业映像.几乎看起来像过去2个月的一些更新正在与我们联系.

这是疯狂的:结果,一旦我在Windows 7机器上安装.net 4.5,WebRequest工作!我们认为,这个罪魁祸首是部署到所有客户端机器的.NET 4.0 Framework的一个缺失补丁.
所以,修补你的机器:)
http://stackoverflow.com/questions/31936904/401-when-calling-web-service-only-on-particular-machines

本站文章除注明转载外,均为本站原创或编译
转载请明显位置注明出处:仅在特定机器上调用Web Service时,c# – 401