在c#.Net 2.0中调用Web服务时发生超时错误

发布于 2024-07-24 08:41:54 字数 657 浏览 3 评论 0原文

我继承了一些代码,并且对处理Web服务不太熟悉。 以下是该项目的设置方式:

在“Web 引用”下,有一个对我们正在使用的 Web 服务的引用。 在该服务的 Reference.cs 文件中,有一个继承自 SoapHttpClientProtocol 的类,该类有一个名为 CandidateAdd() 的函数,该函数调用 this.Invoke (我认为这会进行实际的 Web 方法调用)

然后从以下两个类派生Reference.cs 文件(一个用于生产环境,一个用于开发环境),它们仅包含 GetWebRequest(Uri) 的重写,此处设置

webRequest.KeepAlive = false;
webRequest.MaximumAutomaticRedirections = 30;
System.Net.ServicePointManager.MaxServicePointIdleTime = 18000;
webRequest.AllowAutoRedirect = true;
//webRequest.Timeout = 18000;

并返回 Web 请求对象。

应用程序的性质使得这个 Web 方法每天可能只会被调用 50 次左右,因此服务器并没有陷入困境或其他什么情况,看起来更像是某些设置不正确。

预先感谢您的任何帮助!

I have inherited some code and I'm not very familiar in dealing with web services. Here is how the project is set up:

Under "Web References" there is a reference to the web service we are using. In that service's Reference.cs file there is class that inherits from SoapHttpClientProtocol, this class has a function called CandidateAdd() which calls this.Invoke (I'm thinking this makes the actual web method call)

Two classes then derive from the one in the Reference.cs file (one for the production environment and one for dev) and they only contain an override of GetWebRequest(Uri), here it sets

webRequest.KeepAlive = false;
webRequest.MaximumAutomaticRedirections = 30;
System.Net.ServicePointManager.MaxServicePointIdleTime = 18000;
webRequest.AllowAutoRedirect = true;
//webRequest.Timeout = 18000;

and returns the web request object.

The nature of the application is such that this web method will probably only be called 50 or so times a day, so it isn't like the server is getting very bogged down or anything, it seems more like something is setup incorrectly.

Thanks in advance for any help!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

提笔落墨 2024-07-31 08:41:54

请发布您看到的完整异常,包括所有 InnerException。 例如:

try {
    using (CandidateService svc = new CandidateService()) {
        svc.CandidateAdd();
    }
}
catch (Exception ex) {
    string what_I_should_post = ex.ToString();
}

您可能认为这是显而易见的,但堆栈跟踪可能是一个重要线索。

然后,您需要弄清楚在超时发生时服务正在做什么。 它可能正在执行数据库操作来“添加”“候选者” - 该操作在服务器端是否成功? 然后您可能想尝试找出是什么花了这么长时间。

派生类的结构是我以前从未见过的,但这是一个好主意。 这可能不是问题所在。 我不会在调试过程中弄乱该代码,但如果您对此有疑虑,请暂时将代码从一个类复制到另一个类中。 这样,它们都将具有相同的 WebRequest 参数。

Please post the complete exception you're seeing, including all InnerException. For instance:

try {
    using (CandidateService svc = new CandidateService()) {
        svc.CandidateAdd();
    }
}
catch (Exception ex) {
    string what_I_should_post = ex.ToString();
}

You may think it's obvious, but the stack trace may be a big clue.

You'll then want to figure out what the service is doing while this timeout is happening. It's probably executing a database operation to "add" the "candidate" - does the operation succeed on the server side? You may then want to try to find out what takes it so long.

The structure with the derived classes is something I haven't seen before, but it's a sound idea. That's probably not the problem. I wouldn't mess with that code during debugging, but if you have concerns about it, temnporarily copy the code from the one class into the other. That way, they'll both have the same WebRequest parameters.

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