WCF客户端允许一个操作并行运行,而不是另一个操作?

时间:2014-06-30 17:45:55

标签: c# multithreading wcf-client

我有一个WCF SOAP客户端,它是从服务WSDL生成的。该服务除其他外还提供querybatch操作。它还声称提供多线程请求处理。

在尝试并行化我的客户端的用法时,我看到了一个奇怪的行为:客户端会愉快地发送尽可能多的query个请求,因为我并行告诉它,但它只会发送一个batch一次请求。我正在使用Fiddler观看流量,我可以看到10个开放query请求,但batch请求始终一次开始和结束。

我正在使用Parallel.ForEach代码路径,MaxDegreeOfParallelism设置为10.我不会更改ServicePointManager.DefaultConnectionLimit,但我确实注意到如果我将其设置为少于query ManagedThreadId请求受到限制的线程数。我已经通过查看并行执行路径中的query值来验证TPL正在启动多个线程。

据我所知,与客户端的唯一区别是GET使用HTTP batch方法,POST使用ServiceKnownType方法。这会导致我看到的行为吗?还有其他我可以看的东西吗?

编辑根据要求,以下是相关的客户端代码(我已移除//generated client interface //{... [OperationContract(Action = "", ReplyAction = "*")] [FaultContract(typeof (fault), Action = "", Name = "fault")] [XmlSerializerFormat(SupportFaults = true)] [return: MessageParameter(Name = "return")] QueryResponse query(QueryRequest queryRequest); [OperationContract(Action = "", ReplyAction = "*")] [FaultContract(typeof (fault), Action = "", Name = "fault")] [XmlSerializerFormat(SupportFaults = true)] [return: MessageParameter(Name = "return")] BatchResponse batch(BatchRequest batchRequest); //...} //generated client class //{... public QueryResponse query(QueryRequest queryRequest) { return this.Channel.query(queryRequest); } public BatchResponse batch(BatchRequest batchRequest) { return this.Channel.batch(batchRequest); } //...} 属性)

Creating...{Thread Id}

EDIT2 这是我的调试输出,试图跟踪它。

  在我开始为batch操作组合有效负载之前,

Sending...{Thread Id}被写入控制台

     在调用batch操作之前,

Sent...{Thread Id}行被写入控制台

     在batch操作完成后立即将

1:53:58 PM (Thread 4) 1:53:58 PM (Thread 19) 1:53:58 PM (Thread 20) 1:53:58 PM (Thread 16) 1:53:58 PM (Thread 18) 1:53:58 PM (Thread 17) 1:53:58 PM (Thread 7) 1:53:58 PM (Thread 15) Creating...19 Creating...15 Creating...16 Creating...17 Creating...7 Creating...4 Creating...20 Creating...18 Sending...17 Sending...7 Sending...20 Sending...19 Sending...16 Sending...18 Sending...4 Sending...15 1:53:59 PM (Thread 22) Creating...22 Sending...22 1:53:59 PM (Thread 23) Creating...23 Sending...23 Sent...17 Sent...15 Sent...7 Sent...18 Sent...20 Sent...16 Sent...4 Sent...19 Sent...22 Sent...23 行写入控制台

query

这是此次运行的Fiddler日志:

enter image description here

作为参考,这里是来自Fiddler日志的{{1}}代码路径的剪辑:

enter image description here

0 个答案:

没有答案