多次 Web Service 调用随机导致 401 Unauthorized 响应 [英] Many Web Service calls caused 401 Unauthorized response randomly

查看:30
本文介绍了多次 Web Service 调用随机导致 401 Unauthorized 响应的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用正在调用另一个 Web 服务的 Web 服务.当我的应用程序在短时间内进行大量调用时,它可以运行一个场景.在某个时间点,Web 服务开始抛出错误 401 Unauthorized.这是详细的错误:

I have consuming Web Service that's calling another web service. My Application can run a scenario when it makes a lot of calls in short period of time. At some point of time Web Service starts throwing back error 401 Unauthorized. Here's detailed error:

<Exception>
    <Source>mscorlib</Source>
    <Message>The HTTP request is unauthorized with client authentication scheme 'Negotiate'. The authentication header received from the server was 'Negotiate,NTLM'.</Message>
    <Stack>
Server stack trace: 
   at System.ServiceModel.Channels.HttpChannelUtilities.ValidateAuthentication(HttpWebRequest request, HttpWebResponse response, WebException responseException, HttpChannelFactory`1 factory)
   at System.ServiceModel.Channels.HttpChannelUtilities.ValidateRequestReplyResponse(HttpWebRequest request, HttpWebResponse response, HttpChannelFactory`1 factory, WebException responseException, ChannelBinding channelBinding)
   at System.ServiceModel.Channels.HttpChannelFactory`1.HttpRequestChannel.HttpChannelRequest.WaitForReply(TimeSpan timeout)
   at System.ServiceModel.Channels.RequestChannel.Request(Message message, TimeSpan timeout)
   at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs, TimeSpan timeout)
   at System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage methodCall, ProxyOperationRuntime operation)
   at System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage message)

Exception rethrown at [0]: 
   at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)
   at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData&amp; msgData, Int32 type)
   at KwikTagWebInterface.DMSWebSrv.IWOVServicesSoap.CreateDocuments(CreateDocumentsRequest request)
   at KwikTagWebInterface.DMSWebSrv.WOVServicesSoapClient.CreateDocuments(CreateDocumentsInput CreateDocuments1)
   at KwikTagWebInterface.Controllers.DMSConnector.CreateDocumentProforma(String profIndex, String matter, String userName)
   at KwikTagWebInterface.KTWebServices.TagProformaECover(String profIndex, String matter, String userName, String userDomain)</Stack>
    <InnerException>
      <Source>System</Source>
      <Message>The remote server returned an error: (401) Unauthorized.</Message>
      <Stack>   at System.Net.HttpWebRequest.GetResponse()
   at System.ServiceModel.Channels.HttpChannelFactory`1.HttpRequestChannel.HttpChannelRequest.WaitForReply(TimeSpan timeout)</Stack>
    </InnerException>
  </Exception>

它会抛出几个这样的错误,然后继续正常工作.这些调用之间绝对没有区别,所以我不明白为什么有些调用可以正常工作,有些则不行.

It throws several errors like this and then continue working just fine. There is absolutely no difference between those calls, so I don't understand why some of them works fine and some of them don't.

这是我的配置:

<system.serviceModel>
  <bindings>
    <basicHttpBinding>
      <binding name="IWOVServicesSoap" maxReceivedMessageSize="2097152" maxBufferSize="2097152" maxBufferPoolSize="2097152">
        <security mode="TransportCredentialOnly">
          <transport clientCredentialType="Windows" proxyCredentialType="None" realm="" />
          <message clientCredentialType="UserName" algorithmSuite="Default" />
        </security>
      </binding>
    </basicHttpBinding>
  </bindings>
  <client>
    <endpoint address="http://Server/Application/Services/IWOVServices.asmx"
      binding="basicHttpBinding" bindingConfiguration="IWOVServicesSoap"
      contract="WebSrv.IWOVServicesSoap" name="IWOVServicesSoap" />
  </client>
</system.serviceModel>

请问有什么建议吗?

推荐答案

您可能会受到限制,尽管这是针对这种情况的错误响应代码.不过,这是分布式服务的本质.我建议采用某种重试策略来缓解这个问题.或者引入一些你自己的速率限制来减少你提出请求的频率.或者,如果有一种方法可以批量处理您的请求并只发送 1 个而不是 1000 个,这可能是最佳解决方案.

You might be getting throttled, though that's the wrong response code for such a situation. This is the nature of distributed services, though. I'd recommend employing a retry policy of some kind to mitigate the problem. That or introduce some rate limiting of your own to reduce how frequently you make requests. Or, if there is a way to batch your requests and send just 1 instead of 1,000 that would probably be the optimal solution.

这篇关于多次 Web Service 调用随机导致 401 Unauthorized 响应的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆