简体   繁体   English

用作Web参考(而非服务参考)时增加超时

[英]Increase timeout when consumed as web reference (not service reference)

There are lots of similar questions on StackOverflow. 关于StackOverflow有很多类似的问题。 If this is a duplicate, I would appreciate a little explanation of how to apply other solution in my context please. 如果这是重复的,请对如何在我的上下文中应用其他解决方案进行一些解释。

I have a project that is a WebAPI. 我有一个WebAPI项目。 This WebAPI in turn calls a web service (WSDL), processes the data and returns to the client: 该WebAPI依次调用Web服务(WSDL),处理数据并返回到客户端:

[Client] ---->  [My WebAPI] ----> [WSDL Server]
                                        |
       <--------  [My WebAPI] <---------

The WSDL part is a Java-based service. WSDL部分是基于Java的服务。 The only way we could consume it without issue in VS2015 was to add it as a Web Reference (2.0 in the dialog). 我们可以在VS2015中使用它而不会出现问题的唯一方法是将其添加为Web参考(对话框中为2.0)。 It works perfectly, with strongly-typed values as required, but today we've seen a timeout between My WebApi and WSDL Server . 它可以完美工作,并根据需要使用强类型值,但是今天我们看到My WebApiWSDL Server之间存在超时。

In other answers on SO, I see that the timeout period can be configured in web.config <bindings> or via a proxy, but I can't see how to wire this up given my web.config contents, which differs massively from other peoples. 在SO的其他答案中,我看到可以在web.config <bindings>或通过代理中配置超时期限,但是鉴于我的web.config内容,我看不到如何进行连接,这与其他内容大不相同。人们。 The code below was generated by VS2015 when the WSDL service was consumed: 下面的代码是在使用WSDL服务时由VS2015生成的:

<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>

I also can't find any mention of timeouts in the c# intellisense code. 我也找不到C#intellisense代码中的超时说明。 Any help or pointers would be appreciated. 任何帮助或指针,将不胜感激。 I've read about 12 posts on SO but still can't figure it out. 我已经阅读了12篇关于SO的文章,但仍然无法弄清楚。

I hate to answer my own question but I think I've found the answer (I will remove if not). 我讨厌回答自己的问题,但我想我已经找到了答案(如果没有,我会删除)。 This is obvious, but reading too much on SO actually threw me off course and I was inspecting the wrong class in VS. 这很明显,但是对SO的过多阅读实际上使我偏离了方向,并且我在VS中检查了错误的类。

When consumed, the third-party web service client class GetData() is forced to derive from SoapHttpClientProtocol . 使用时,第三方Web服务客户端类GetData()被强制从SoapHttpClientProtocol派生。 This class derives from HttpWebClientProtocol , derived from WebClientProtocol . 该类派生自HttpWebClientProtocol ,派生自WebClientProtocol

WebClientProtocol has a public property Timeout , expressed in milliseconds. WebClientProtocol具有公共属性Timeout ,以毫秒为单位。

Indicates the time an XML Web service client waits for the reply to a synchronous XML Web service request to arrive (in milliseconds). 指示XML Web服务客户端等待对同步XML Web服务请求的答复到达的时间(以毫秒为单位)。

The time out, in milliseconds, for synchronous calls to the XML Web service. 同步调用XML Web服务的超时(以毫秒为单位)。 The default is 100000 milliseconds. 默认值为100000毫秒。

Setting the Timeout property to Timeout.Infinite indicates that the request does not time out. 将Timeout属性设置为Timeout.Infinite表示请求不会超时。 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. 即使XML Web服务客户端可以将Timeout属性设置为不超时,Web服务器仍可以使请求在服务器端超时。

Therefore the Timeout property is available directly from code when instantiated as a web service client, which I believe is due to the magic of VS: 因此,当实例化为Web服务客户端时,可以直接从代码中获取Timeout属性,我认为这是因为VS的神奇之处:

SomeComsumedWebService wsc = new SomeComsumedWebService();
SomeComsumedWebService.Timeout = 600000; // 10 minutes
var obj = SomeComsumedWebService.MethodToGetData();

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

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