简体   繁体   English

WCF 服务接受并发请求

[英]WCF service accepting concurrent requests

I am new to WCF web services.我是 WCF Web 服务的新手。 My requirement is to create a WCF service which is a wrapper for third-party COM dll object.我的要求是创建一个 WCF 服务,它是第三方 COM dll 对象的包装器。

Let's assume that the dll takes 5 sec to calculate one particular input.让我们假设 dll 需要 5 秒来计算一个特定的输入。

When I created the service and tested it (using the WCF test client) the scenario I see that I am not able to send 2nd request until first request is completed.当我创建服务并测试它(使用 WCF 测试客户端)时,我看到在第一个请求完成之前我无法发送第二个请求。

So I was thinking to start a new thread for consuming the com functionality and call a callback function once done.所以我想启动一个新线程来使用 com 功能并在完成后调用回调函数。 I want to send the response and end request in this callback function.我想在这个回调函数中发送响应和结束请求。 This is for every request that hits the WCF service.这是针对每个命中 WCF 服务的请求。

I have tested this, but problem is I am getting the response without completing the request.我已经对此进行了测试,但问题是我没有完成请求就得到了响应。

I want current thread to wait until the calculations are done and also accept other requests in parallel我希望当前线程等待计算完成并同时接受其他请求

Can you please let me know how I can fix this considering the performance?考虑到性能,你能告诉我如何解决这个问题吗?

My service will be consumed by multiple SAP Portals clients via SAP PI我的服务将通过 SAP PI 被多个 SAP Portals 客户端使用

The concurrencymode for service can be set applying [ServiceBehavior] attribute on Service Class implementing ServiceContract.可以在实现 ServiceContract 的服务类上应用 [ServiceBehavior] 属性来设置服务的并发模式。 http://msdn.microsoft.com/en-us/library/system.servicemodel.concurrencymode(v=vs.110).aspx http://msdn.microsoft.com/en-us/library/system.servicemodel.concurrencymode(v=vs.110).aspx

However, in your situation where you access a COM component in service operation, I'd first check the Threading model for COM component ie does it implement Apartment (STA) or MTA.但是,在您访问服务操作中的 COM 组件的情况下,我会首先检查 COM 组件的线程模型,即它是否实现了 Apartment (STA) 或 MTA。 If COM component implements Apartment threading model, COM call invocation will be serialized.如果 COM 组件实现了 Apartment 线程模型,则 COM 调用将被序列化。 Thus, changing WCF ConcurrencyMode will not have any impact.因此,更改 WCF ConcurrencyMode 不会产生任何影响。

HTH, Amit Bhatia HTH,阿米特·巴蒂亚

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM