调用 Web 服务超时但数据传输仍完成
尽管在 web.config 文件中设置了非常高的值,但我从网页调用我的 Web 服务并超时。 当文件通常相当大但但文件仍在完全上传(就好像没有发生超时一样)时,会间歇性地发生这种情况。 下面是我的 .aspx 文件中的一个函数,它调用我的 ASMX 代理类:
private void UploadFile(HttpPostedFile postedFile, string fileNameOnly)
{
// create an instance of the proxy class to talk to our service; calling it client:
string strURI = string.Empty;
WSproxyProject.ASMXProxy.FileService client = new WSproxyProject.ASMXProxy.FileService();
try
{
BinaryReader b = new BinaryReader(postedFile.InputStream);
byte[] binData = b.ReadBytes(numBytes);
strURI = client.UploadFile(binData, fileNameOnly, binData.Length);
txtURI.Text = strURI;
LogText("SUCCESS: " + fileNameOnly + " has been uploaded. URI=" + strURI);
}
catch (Exception ex)
{
LogText("UPLOAD ERROR: " + ex.Message.ToString());
}
}
请注意,本地主机上的 Web 服务调用另一个实际存储最终数据的 Web 服务。 我在以下所有位置的 web.config 中都有以下executionTimeout 设置:
- web 客户端项目上的 web.config(myWebService 的调用者)
- myWebService 上的 web.config(vendorWebService 的调用者)
vendorWebService 上的 web.config (驻留在我的 LAN 中的另一台服务器上)
上面的代码块捕获的异常显示 ex.Source 为 System.Web.Services,ex.Message 为:
操作已超时
I'm calling my webservice from a web page and getting a timeout despite setting very high values in my web.config files. This occurs intermittently when the file is usually pretty large but yet the file is still getting uploaded completely (as if the timeout DID NOT occur). Here is a function in my .aspx file which calls my ASMX proxy class:
private void UploadFile(HttpPostedFile postedFile, string fileNameOnly)
{
// create an instance of the proxy class to talk to our service; calling it client:
string strURI = string.Empty;
WSproxyProject.ASMXProxy.FileService client = new WSproxyProject.ASMXProxy.FileService();
try
{
BinaryReader b = new BinaryReader(postedFile.InputStream);
byte[] binData = b.ReadBytes(numBytes);
strURI = client.UploadFile(binData, fileNameOnly, binData.Length);
txtURI.Text = strURI;
LogText("SUCCESS: " + fileNameOnly + " has been uploaded. URI=" + strURI);
}
catch (Exception ex)
{
LogText("UPLOAD ERROR: " + ex.Message.ToString());
}
}
Please note that my web service on localhost calls another web service which actually stores the final data. I have the following executionTimeout setting in of the web.config in all of the following places:
- web.config on my web client project (caller of myWebService)
- web.config on myWebService (caller of vendorWebService)
web.config on vendorWebService (resides on another server in my LAN)
The exception caught by the code block above shows the ex.Source to be System.Web.Services and the ex.Message to be:
The operation has timed out
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您在方法中设置 Web 服务超时长度,会发生什么情况?
也许您还需要为 FileService 使用的其他 Web 服务设置类似的超时属性。
我必须对使用功能不足的开发数据库的 Web 服务调用执行此操作。 我宁愿让 Web 服务准备好执行比需要的时间更长的时间,也不愿抛出异常。
祝你好运。
What happens if you set the Web Service timeout length in your method?
Perhaps you would also need to set similar timeout properties to other Web Services that the FileService uses.
I had to do that for a Web Service call that utilized an under powered development database. I'd rather have a Web Service prepared to execute longer than needed than throw an exception.
Good luck.
一些头脑风暴:
希望里面有帮助。
Some brainstorming:
Hope something in there helps.