【发布时间】:2014-10-28 09:09:35
【问题描述】:
我需要通过另一个 Web 服务向一个 Web 服务并行运行多个 HTTP Web 请求。
我在这里找到了相关的相关解决方案: Trying to run multiple HTTP requests in parallel, but being limited by Windows (registry) Trying to run multiple HTTP requests in parallel, but being limited by Windows (registry)
我的问题和这个问题类似。
之前,我通过 C# WinForms 应用程序从我的机器并行调用 Web 服务多次。 当时,使用 ServicePointManager.DefaultConnectionLimit 解决了我的问题。
现在,我的要求发生了变化。 还有另一个应用程序,现在是一个只有 1 个网页的 Web 服务,由多个用户并行调用。此 Web Service 调用另一个 Web Service ,因此我们有多个并行调用从 Web Server 机器发出。
我是 Web 中的菜鸟,所以我不知道我需要在哪里设置 Web 服务上的 ServicePointManager.DefaultConnectionLimit。 (我是在我的 Winforms 应用程序的 Main() 中做的。)
我的问题是在哪里指定 ServicePointManager.DefaultConnectionLimit ??
Web 服务没有 Main(),它只有一个 Global.asax,其中大部分包含代码 sn-ps 和管道。
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
public Global()
{
InitializeComponent();
}
protected void Application_Start(Object sender, EventArgs e)
{
AppDomain.CurrentDomain.UnhandledException +=new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);
this.Initialise();
}
#region Web Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
//
// Global
//
this.Error += new System.EventHandler(this.Global_Error);
}
#endregion
private void Global_Error(object sender, System.EventArgs e)
{
HandleLastError();
}
protected void Application_Error(Object sender, EventArgs e)
{
HandleLastError();
}
private void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
{
Exception unhandledException = (Exception)e.ExceptionObject;
HandleException(unhandledException);
}
private void HandleLastError()
{
Exception lastError = Server.GetLastError();
HandleException(lastError);
}
private static void HandleException(Exception exception)
{
Logger logger = new Logger(typeof(CreditCheck));
string lastErrorMessage = (exception == null ? "No exception" : exception.Message);
logger.Error(lastErrorMessage, exception);
}
我的问题是在哪里指定 ServicePointManager.DefaultConnectionLimit ??
只有一个 .asmx(和 .asmx.cs)文件,它只包含我工作的函数。 该函数应该调用其他 Web 服务。 每次点击 Web 服务时都会调用此函数(在 1 秒内多次 - 大约 10 次),所以我不确定是否可以在此处指定 ServicePointManager.DefaultConnectionLimit,因为这意味着每次点击时都会重置它。
此外,它托管在共享服务器上,因此我不想弄乱注册表项值,但我很乐意以编程方式进行此更改。
任何帮助将不胜感激。
【问题讨论】:
标签: c# web-services wcf httprequest webservice-client