【问题标题】:How to increase timeout while querying data from WebService从 WebService 查询数据时如何增加超时
【发布时间】:2017-12-09 09:54:28
【问题描述】:

我可以在控制器的 ActionMethod 中查询 web 服务,但无法在应用程序启动时查询它。

问题描述: 我正在 ASP.net MVC 5 上开发一个 WebApplication,它使用从 SOAP Web 服务Autotask API 检索到的数据。让我在这里说一下,在用户执行其他操作之前,必须从 API 加载/缓存一些记录。

所以对于 WebApp 和 Webservice 之间的通信,

  • 我使用提供的 WSDL 添加了 Service Reference
  • 从中创建了代理类,在开发过程中我一直在 Controller 的 ActionMethods 中调用 Webservice。
  • 因此,在用户单击给定链接的任何时间查看视图中,都会调用 Web 服务。检索到的记录列表被缓存在应用程序中,这样下次我们就不必再次调用 Webservice。它工作正常。

我正在努力实现的目标

在生产中,最好在应用程序启动时加载这些记录。

所以我将 Webservice 的调用从控制器的 ActionMethod 转移到 Global.asax.cs 中的 Application_Start() 方法。

但是当我启动应用程序并从 Web 服务查询数据时。它导致错误

内容类型text/html;响应消息的charset=utf-8 与绑定的内容类型不匹配(text/xml; charset=utf-8)

由于我期待 XML 格式的数据记录,服务器返回错误 The remote server returned an error: (500) Internal Server Error.,说明“用户名和密码不正确”

但我相信实际情况并非如此。因为两个坚实的原因

  1. 如上所述,我已使用 Controller 的 ActionMethod 中的相同凭据成功连接到 Webservice。
  2. 由于以下例外。

服务器堆栈跟踪: 在 System.ServiceModel.Channels.HttpChannelUtilities.ValidateRequestReplyResponse(HttpWebRequest 请求,HttpWebResponse 响应,HttpChannelFactory1 factory, WebException responseException, ChannelBinding channelBinding) at System.ServiceModel.Channels.HttpChannelFactory1.HttpRequestChannel.HttpChannelRequest.WaitForReply(时间跨度超时) 在 System.ServiceModel.Channels.RequestChannel.Request(消息消息,TimeSpan 超时) 在 System.ServiceModel.Dispatcher.RequestChannelBinder.Request(消息消息,TimeSpan 超时) 在 System.ServiceModel.Channels.ServiceChannel.Call(字符串操作,布尔单向,ProxyOperationRuntime 操作,Object[] 输入,Object[] 输出,TimeSpan 超时) 在 System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage 方法调用,ProxyOperationRuntime 操作) 在 System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage 消息)

还有一个内部异常。

在 System.Net.HttpWebRequest.GetResponse() 在 System.ServiceModel.Channels.HttpChannelFactory`1.HttpRequestChannel.HttpChannelRequest.WaitForReply(TimeSpan 超时)

对我来说,它表明请求超时已过期。我尝试将绑定配置修改为以下内容,如WCF Service, How to increase the timeout?

中所述
<system.serviceModel>
<bindings>
  <basicHttpBinding>
    <binding name="ATWS15" />
    <binding name="IncreasedTimeout" sendTimeout="00:10:00"></binding>
  </basicHttpBinding>
</bindings>
<client>
  <endpoint address="http://webservices.address.toApi.net/atws.asmx"
    binding="basicHttpBinding" bindingConfiguration="IncreasedTimeout" contract="AutoTaskProxy.ATWS15"
     />
</client>

如果有人可以帮助我,我在这里做错了什么。?我可以在控制器的 ActionMethod 中查询 webservice,但无法在应用程序启动时查询它

【问题讨论】:

    标签: c# web-services asp.net-mvc-5 timeout


    【解决方案1】:

    你有响应超时异常,尝试增加receiveTimeout

    <bindings>
      <basicHttpBinding>
        <binding name="ATWS15" />
        <binding name="IncreasedTimeout" sendTimeout="00:10:00" receiveTimeout="00:10:00"></binding>
      </basicHttpBinding>
    </bindings>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-08-14
      • 1970-01-01
      • 2015-03-27
      • 2023-02-06
      相关资源
      最近更新 更多