简体   繁体   English

WCF错误401仅在某些PC上未经授权

[英]WCF Error 401 Unauthorized only on some pcs

I have a WinForms app that calls a WCF service hosted on IIS7. 我有一个WinForms应用程序,该应用程序调用IIS7上托管的WCF服务。 For some reason, computers attached to the client network get a 401 Unauthorized error when trying to connect to the WCF Service through the WinForms app. 由于某些原因,尝试通过WinForms应用程序连接到WCF服务时,连接到客户端网络的计算机会收到401未经授权的错误。 I have spent quite a bit of time trying to figure this out and this is what I have found out so far. 我花了很多时间试图解决这个问题,这是我到目前为止发现的结果。

  • The WinForms app receives the WCF service data on any other PC not on the client network. WinForms应用程序在客户端网络以外的任何其他PC上接收WCF服务数据。
  • From the client network, I can browse to the WCF service through a web browser just fine. 从客户端网络,我可以通过Web浏览器浏览到WCF服务。
  • From the client network, I can browse to a service method and get the "Method not allowed" error as expected. 从客户端网络,我可以浏览到一种服务方法,并按预期获得“方法不允许”错误。

Also, it should be noted that the WCF service is using REST instead of SOAP. 另外,应该注意WCF服务正在使用REST而不是SOAP。

Here is the code I use to do all the service calls: 这是我用来进行所有服务调用的代码:

            byte[] dataStream = Encoding.UTF8.GetBytes(strParameters);
            WebRequest webRequest = WebRequest.Create(strUrl + strFunction);
            webRequest.Method = "POST";
            webRequest.ContentType = "application/json";
            webRequest.ContentLength = dataStream.Length;
            Stream newStream = webRequest.GetRequestStream();

            newStream.Write(dataStream, 0, dataStream.Length);
            newStream.Close();
            WebResponse response = webRequest.GetResponse();
            Stream responseStream = response.GetResponseStream();
            StreamReader responseReader = new System.IO.StreamReader(responseStream, Encoding.UTF8);
            string responseString = responseReader.ReadToEnd();

Does anyone have any clues as to why I would be getting the 401 error only on the Client's network? 有人对我为什么仅在客户端网络上出现401错误有任何线索吗?

My suggestion would be to try the call via fiddler from the clients machine and validate if you can get the expected result via a POST. 我的建议是尝试通过客户端计算机上的提琴手进行呼叫,并验证是否可以通过POST获得预期的结果。 If this is successful I would look into how you are hosting the service in IIS. 如果成功,我将调查您如何在IIS中托管服务。 I have seen on several occasions where the issue was Anonymous or Basic Authentication was turned off which caused similar issues. 我曾多次看到问题是匿名或基本身份验证被关闭而导致了类似的问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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