gpt4 book ai didi

c# - Linq AsParallel() 可以过早地处理 SoapHttpClientProtocol 对象吗?

转载 作者:行者123 更新时间:2023-11-30 16:10:11 26 4
gpt4 key购买 nike

在我正在处理的 ASP.Net MVC 4 Web 应用程序中。我有一个页面基本上通过从 SOAP 服务获取数据来生成报告。

我的代码基本上是这样的

List<CustomThings> serverInfos = ServerInfos;
serverInfos.AsParallel().ForAll(srvInfo =>
{
SoapHttpClientProtocol soapProxy = CreateProxy(srvInfo);
//call make soap calls through the soap client
//store results in the proper places
}

我在这里使用 AsParallel 的原因是因为以串行方式通过 HTTP 执行多个请求需要很长时间。我应该指出,这段代码确实有效,尽管偶尔会有效

是否有可能以不可预测的方式处理事情,而 PLINQ 不是我在这里尝试做的事情的好解决方案?

是否有可能另一个线程问题会导致错误,使 soap 客户端“放弃”?

附加信息

这个特定的 soap 代理正在与 ArcGIS Server 对话。通常,您可以检查服务器日志并查看特定请求何时发起以及请求是否失败。这些日志中没有显示任何内容。


这是我从 AsParallel 代码中获得的内部异常堆栈跟踪示例。

Exception: System.AggregateException: One or more errors occurred. ---> System.Net.WebException: The underlying connection was closed: A connection that was expected to be kept alive was closed by the server. ---> System.IO.IOException: Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host. ---> System.Net.Sockets.SocketException: An existing connection was forcibly closed by the remote host at System.Net.Sockets.Socket.Receive(Byte[] buffer, Int32 offset, Int32 size, SocketFlags socketFlags) at System.Net.Sockets.NetworkStream.Read(Byte[] buffer, Int32 offset, Int32 size) --- End of inner exception stack trace --- at System.Net.Sockets.NetworkStream.Read(Byte[] buffer, Int32 offset, Int32 size) at System.Net.PooledStream.Read(Byte[] buffer, Int32 offset, Int32 size) at System.Net.Connection.SyncRead(HttpWebRequest request, Boolean userRetrievedStream, Boolean probeRead) --- End of inner exception stack trace --- at System.Web.Services.Protocols.WebClientProtocol.GetWebResponse(WebRequest request) at System.Web.Services.Protocols.HttpWebClientProtocol.GetWebResponse(WebRequest request) at System.Web.Services.Protocols.SoapHttpClientProtocol.Invoke(String methodName, Object[] parameters) at ESRI.ArcGIS.SOAP.FeatureServerProxy.Query(Int32 LayerOrTableID, String DefinitionExpression, QueryFilter QueryFilter, ServiceDataOptions ServiceDataOptions, String GdbVersion, Double MaximumAllowableOffset) at System.Linq.Parallel.SelectQueryOperator2.SelectQueryOperatorResults.GetElement(Int32
index) at System.Linq.Parallel.QueryResults
1.get_Item(Int32 index) at System.Linq.Parallel.PartitionedDataSource1.ListContiguousIndexRangeEnumerator.MoveNext(T&
currentElement, Int32& currentKey) at
System.Linq.Parallel.PipelineSpoolingTask
2.SpoolingWork() at System.Linq.Parallel.SpoolingTaskBase.Work() at System.Linq.Parallel.QueryTask.BaseWork(Object unused) at System.Linq.Parallel.QueryTask.<.cctor>b__0(Object o) at System.Threading.Tasks.Task.InnerInvoke() at System.Threading.Tasks.Task.Execute()

最佳答案

PLINQ 甚至不知道您的连接对象存在。它无法关闭它。

仔细阅读消息:

An existing connection was forcibly closed by the remote host.

服务器以意外方式关闭了连接。您的客户没有错。

准确解释异常是一项基本的调试技巧。此信息就在异常消息中。

也许您产生了过多的负载。设置可持续的并行度。默认启发式算法适用于 CPU 工作,而不适用于 IO。

.WithDegreeOfParallelism(10)

A connection that was expected to be kept alive was closed by the server.

这可能意味着服务器不支持 HTTP keep alive。

关于c# - Linq AsParallel() 可以过早地处理 SoapHttpClientProtocol 对象吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26307371/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com