编程语言
首页 > 编程语言> > Linq AsParallel()是否可以过早地处理SoapHttpClientProtocol对象?

Linq AsParallel()是否可以过早地处理SoapHttpClientProtocol对象?

作者:互联网

在我正在使用的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客户端“放弃”的错误?

附加信息

该特定的肥皂代理正在与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保持活动状态.

标签:asp-net-mvc-4,soap-client,plinq,arcgis-server,c
来源: https://codeday.me/bug/20191121/2049756.html