作为 Web 参考(而非服务参考)使用时增加超时
Increase timeout when consumed as web reference (not service reference)
Whosebug 上有很多 similar 个问题。如果这是重复的,我将不胜感激,请解释一下如何在我的上下文中应用其他解决方案。
我有一个 WebAPI 项目。此 WebAPI 依次调用 Web 服务 (WSDL)、处理数据并 returns 到客户端:
[Client] ----> [My WebAPI] ----> [WSDL Server]
|
<-------- [My WebAPI] <---------
WSDL 部分是基于 Java 的服务。我们可以在 VS2015 中毫无问题地使用它的唯一方法是将它添加为 Web 引用(对话框中的 2.0)。它完美地工作,根据需要使用强类型值,但今天我们看到 My WebApi
和 WSDL Server
之间的超时。
在关于 SO 的其他答案中,我看到可以在 web.config <bindings>
中或通过代理配置超时期限,但鉴于我的 web.config 内容,与其他民族大不相同。下面的代码是VS2015在消费WSDL服务时生成的:
<system.serviceModel>
<bindings />
<client />
</system.serviceModel>
<applicationSettings>
<MyWebAPI.Properties.Settings>
<setting name="MyWebAPIs_ThirdPartyWSDLService_GetData" serializeAs="String">
<value>https://wsdl.domain.com/webservices/services/GetData</value>
</setting>
</MyWebAPIs.Properties.Settings>
</applicationSettings>
我在 c# 智能感知代码中也找不到任何关于超时的提及。任何帮助或指示将不胜感激。我已经阅读了关于 SO 的大约 12 篇文章,但仍然无法弄清楚。
我不想回答我自己的问题,但我想我找到了答案(如果没有我会删除)。这很明显,但是在 SO 上阅读太多实际上让我偏离了方向,我在 VS 中检查了错误的 class。
使用时,第三方 Web 服务客户端 class GetData()
被迫派生自 SoapHttpClientProtocol
。这个class来源于HttpWebClientProtocol
,来源于WebClientProtocol
。
WebClientProtocol有一个public属性Timeout
,以毫秒表示。
Indicates the time an XML Web service client waits for the reply to a synchronous XML Web service request to arrive (in milliseconds).
The time out, in milliseconds, for synchronous calls to the XML Web service. The default is 100000 milliseconds.
Setting the Timeout property to Timeout.Infinite indicates that the request does not time out. Even though an XML Web service client can set the Timeout property to not time out, the Web server can still cause the request to time out on the server side.
因此,当实例化为 Web 服务客户端时,Timeout
属性 可直接从代码获得,我相信 是由于 VS 的魔力:
SomeComsumedWebService wsc = new SomeComsumedWebService();
SomeComsumedWebService.Timeout = 600000; // 10 minutes
var obj = SomeComsumedWebService.MethodToGetData();
Whosebug 上有很多 similar 个问题。如果这是重复的,我将不胜感激,请解释一下如何在我的上下文中应用其他解决方案。
我有一个 WebAPI 项目。此 WebAPI 依次调用 Web 服务 (WSDL)、处理数据并 returns 到客户端:
[Client] ----> [My WebAPI] ----> [WSDL Server]
|
<-------- [My WebAPI] <---------
WSDL 部分是基于 Java 的服务。我们可以在 VS2015 中毫无问题地使用它的唯一方法是将它添加为 Web 引用(对话框中的 2.0)。它完美地工作,根据需要使用强类型值,但今天我们看到 My WebApi
和 WSDL Server
之间的超时。
在关于 SO 的其他答案中,我看到可以在 web.config <bindings>
中或通过代理配置超时期限,但鉴于我的 web.config 内容,与其他民族大不相同。下面的代码是VS2015在消费WSDL服务时生成的:
<system.serviceModel>
<bindings />
<client />
</system.serviceModel>
<applicationSettings>
<MyWebAPI.Properties.Settings>
<setting name="MyWebAPIs_ThirdPartyWSDLService_GetData" serializeAs="String">
<value>https://wsdl.domain.com/webservices/services/GetData</value>
</setting>
</MyWebAPIs.Properties.Settings>
</applicationSettings>
我在 c# 智能感知代码中也找不到任何关于超时的提及。任何帮助或指示将不胜感激。我已经阅读了关于 SO 的大约 12 篇文章,但仍然无法弄清楚。
我不想回答我自己的问题,但我想我找到了答案(如果没有我会删除)。这很明显,但是在 SO 上阅读太多实际上让我偏离了方向,我在 VS 中检查了错误的 class。
使用时,第三方 Web 服务客户端 class GetData()
被迫派生自 SoapHttpClientProtocol
。这个class来源于HttpWebClientProtocol
,来源于WebClientProtocol
。
WebClientProtocol有一个public属性Timeout
,以毫秒表示。
Indicates the time an XML Web service client waits for the reply to a synchronous XML Web service request to arrive (in milliseconds).
The time out, in milliseconds, for synchronous calls to the XML Web service. The default is 100000 milliseconds.
Setting the Timeout property to Timeout.Infinite indicates that the request does not time out. Even though an XML Web service client can set the Timeout property to not time out, the Web server can still cause the request to time out on the server side.
因此,当实例化为 Web 服务客户端时,Timeout
属性 可直接从代码获得,我相信 是由于 VS 的魔力:
SomeComsumedWebService wsc = new SomeComsumedWebService();
SomeComsumedWebService.Timeout = 600000; // 10 minutes
var obj = SomeComsumedWebService.MethodToGetData();