调用 Web 服务超时但数据传输仍完成

发布于 2024-07-15 05:19:55 字数 1289 浏览 2 评论 0原文

尽管在 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 设置:

  1. web 客户端项目上的 web.config(myWebService 的调用者)
  2. myWebService 上的 web.config(vendorWebService 的调用者)
  3. 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:

  1. web.config on my web client project (caller of myWebService)
  2. web.config on myWebService (caller of vendorWebService)
  3. 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

凶凌 2024-07-22 05:19:55

如果您在方法中设置 Web 服务超时长度,会发生什么情况?

...
WSproxyProject.ASMXProxy.FileService client = new WSproxyProject.ASMXProxy.FileService();
    client.Timeout = 9999999;
    try
    ...

也许您还需要为 FileService 使用的其他 Web 服务设置类似的超时属性。

我必须对使用功能不足的开发数据库的 Web 服务调用执行此操作。 我宁愿让 Web 服务准备好执行比需要的时间更长的时间,也不愿抛出异常。

祝你好运。

What happens if you set the Web Service timeout length in your method?

...
WSproxyProject.ASMXProxy.FileService client = new WSproxyProject.ASMXProxy.FileService();
    client.Timeout = 9999999;
    try
    ...

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.

太傻旳人生 2024-07-22 05:19:55

一些头脑风暴:

  • 您是否考虑过哪个 Web 服务或客户端超时了? 堆栈跟踪显示什么?
  • 每个人开始这一过程的时间都略有不同。 他们的暂停时间相同吗?
  • 文件完整吗? 它的大小可能是正确的,但可能已损坏。
  • 我知道这听起来很愚蠢,但是是否有一个永无休止的循环或循环比您想象的在某个地方持续的时间更长?

希望里面有帮助。

Some brainstorming:

  • Have you thought about which web service or client is timing out? What does the stack trace show?
  • Each one would begin the process at a slightly different time. Do they have equal time-outs?
  • Is the file complete? It could be the right size, but be corrupted.
  • I know it sounds silly, but is there a never-ending loop or loop that goes for longer than you think it does somewhere?

Hope something in there helps.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文