【发布时间】:2013-11-12 07:26:16
【问题描述】:
我有一个包含很多方法的 Web 服务 (.asmx)。 我想增加一种特定方法的超时,而不更改其他方法的超时。 有可能吗?
【问题讨论】:
-
您是否在客户端调用您的网络方法? (通过 ajax)
标签: c# asp.net .net web-services asmx
我有一个包含很多方法的 Web 服务 (.asmx)。 我想增加一种特定方法的超时,而不更改其他方法的超时。 有可能吗?
【问题讨论】:
标签: c# asp.net .net web-services asmx
尝试阅读此guide 以提高 Web 服务性能 - 超时。
它描述了在代理、构造函数和方法级别为 Web 服务的异步和同步调用定义超时的不同方法。
希望那里有对你有用的东西!
来自指南:
同步方法
或者您可以在方法级别设置它以进行长时间运行的调用。
public string LengthyProc(int sleepTime) {
this.Timeout = 10000; //10 seconds
object[] results = this.Invoke("LengthyProc", new object[] {sleepTime});
return ((string)(results[0]));
}
异步方法 - 更多关于这种方法here
MyWebServ obj = new MyWebServ();
IAsyncResult ar = obj.BeginFunCall(5,5,null,null);
// wait for not more than 2 seconds
ar.AsyncWaitHandle.WaitOne(2000,false);
if (!ar.IsCompleted) //if the request is not completed {
WebClientAsyncResult wcar = (WebClientAsyncResult)ar;
wcar.Abort();//abort the call to web service
}
else
{ //continue processing the results from web service }
【讨论】: