c# - 作为 Web 引用(而非服务引用)使用时增加超时

标签 c# asp.net web-services wsdl

有很多 similar StackOverflow 上的问题。如果这是重复的,请解释一下如何在我的上下文中应用其他解决方案,我将不胜感激。

我有一个 WebAPI 项目。此 WebAPI 依次调用 Web 服务 (WSDL)、处理数据并返回给客户端:

[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# 智能感知代码中也找不到任何关于超时的信息。任何帮助或指示将不胜感激。我已经阅读了大约 12 篇关于 SO 的文章,但仍然无法理解。

最佳答案

我不想回答我自己的问题,但我想我已经找到了答案(如果找不到我会删除)。这很明显,但是阅读太多关于 SO 的文章实际上让我偏离了方向,我在 VS 中检查了错误的类。

使用时,第三方 Web 服务客户端类 GetData() 被迫派生自 SoapHttpClientProtocol。该类派生自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();

关于c# - 作为 Web 引用(而非服务引用)使用时增加超时,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37208687/

相关文章:

c# - Ionic.Zip 抛出意外和奇怪的错误

web-services - Powershell 和 XMLRPC

c# - 如何将 WAVE_MAPPER 音频线与其音频设备关联

c# - Entity Framework 中实体的内部访问使得查询崩溃时的简单 linq

c# - 程序保存文件但不删除同名的旧文件

asp.net - 我如何对已经内置到 dll 中的程序集进行签名,特别是 flute.dll

javascript - Jquery 获取表 gridview 中所有选中行的值

javascript - Jquery 函数不适用于 TextArea

java - HTTPS 主机名错误 : should be <xxx. xxx.xxx.xxx>,检查 URLSpoofing。传递的主机名是什么?

java - 跨平台传输类型对象