Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/314.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何并行地从WCF客户端向WCF服务进行异步调用_C#_Wcf_Throttling - Fatal编程技术网

C# 如何并行地从WCF客户端向WCF服务进行异步调用

C# 如何并行地从WCF客户端向WCF服务进行异步调用,c#,wcf,throttling,C#,Wcf,Throttling,我正在编写一个服务,它有一个运行时间相对较长的调用。客户机需要能够发出彼此并行运行的连续请求,并且出于某种原因,我的服务不会同时执行这些请求,除非调用是从不同的客户机执行的。我正在试图找出我缺少的配置设置 我正在使用NetCPBinding。我的节流配置是: <serviceThrottling maxConcurrentInstances="10" maxConcurrentCalls="10" maxConcurrentSessions="10"/> 在客户机中,我连续进行两次

我正在编写一个服务,它有一个运行时间相对较长的调用。客户机需要能够发出彼此并行运行的连续请求,并且出于某种原因,我的服务不会同时执行这些请求,除非调用是从不同的客户机执行的。我正在试图找出我缺少的配置设置

我正在使用NetCPBinding。我的节流配置是:

<serviceThrottling maxConcurrentInstances="10" maxConcurrentCalls="10" maxConcurrentSessions="10"/>
在客户机中,我连续进行两次异步调用:

openProxy();

//call 1)
                proxy.PrintCustomerHistory(customerListOne, @"c:\DestinationOne\");

//call 2)
                proxy.PrintCustomerHistory(customerListTwo, @"c:\DestinationTwo\");
在服务上,第二个操作仅在第一个操作结束后开始。但是,如果我执行来自不同客户端的两个调用,它们都会由服务并发执行


我错过了什么?我曾假设,通过将我的服务类标记为“PerCall”,调用1和调用2将各自接收自己的InstanceContext,因此在不同的线程上并发执行。

您需要使客户端调用异步。如果您使用的是VS 2012,则可以在服务引用中启用基于任务的异步调用,然后通过以下方式调用:

var task1 = proxy.PrintCustomerHistoryAsync(customerListOne, @"c:\DestinationOne\");
var task2 = proxy.PrintCustomerHistoryAsync(customerListTwo, @"c:\DestinationTwo\");

// The two tasks are running, if you need to wait until they're done:
await Task.WhenAll(task1, task2);

谢谢你的回复。由于以下注释,我认为调用已经是异步的:
[OperationContract(IsOneWay=true)]
我还不熟悉“基于任务的异步”调用以及它们与我已经尝试过的调用的区别。你有阅读建议吗?谢谢见MS文档:“指定操作为单向操作仅意味着没有响应消息。。。如果客户端需要非阻塞调用,请生成AsyncPattern操作:谢谢,Paul。。。这是我困惑的部分原因。发布这个问题的人:似乎和我有相反的问题。使用PerCall/ConcurrencyMode.Single,他希望他的服务以FIFO的形式执行每个请求,但根据他的说法,当从循环中调用时,它们会并发执行。ErnieL建议的解决方案是将MaxConcurrentInstances设置为1。无论如何,我会跟随你的链接,尝试一下AsyncPattern。有人能再来一次吗?我试过里德的建议,但没用。问题不在于我的客户在第一次呼叫完成之前阻止它,然后允许进行第二次呼叫。问题是两个调用都是一个接一个地进行的,但服务确保第一个调用在开始处理第二个调用之前完成。客户端调用已经是异步的(客户端在不等待服务的情况下继续)。服务端是否缺少一些配置?@Sean在您的服务器上,为什么不使用
InstanceContextMode.Single
ConcurrencyMode.Multiple
var task1 = proxy.PrintCustomerHistoryAsync(customerListOne, @"c:\DestinationOne\");
var task2 = proxy.PrintCustomerHistoryAsync(customerListTwo, @"c:\DestinationTwo\");

// The two tasks are running, if you need to wait until they're done:
await Task.WhenAll(task1, task2);