简体   繁体   中英

Increase timeout when consumed as web reference (not service reference)

There are lots of similar questions on 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. This WebAPI in turn calls a web service (WSDL), processes the data and returns to the client:

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

The WSDL part is a Java-based service. The only way we could consume it without issue in VS2015 was to add it as a Web Reference (2.0 in the dialog). It works perfectly, with strongly-typed values as required, but today we've seen a timeout between My WebApi and WSDL 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. The code below was generated by VS2015 when the WSDL service was consumed:

<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. Any help or pointers would be appreciated. I've read about 12 posts on SO but still can't figure it out.

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.

When consumed, the third-party web service client class GetData() is forced to derive from SoapHttpClientProtocol . This class derives from HttpWebClientProtocol , derived from WebClientProtocol .

WebClientProtocol has a public property Timeout , expressed in milliseconds.

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.

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:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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