开发者

WCF multithreaded calls

开发者 https://www.devze.com 2022-12-26 16:03 出处:网络
We have developed a multithreaded server that recieves data from multiple client and calls different WCF services.

We have developed a multithreaded server that recieves data from multiple client and calls different WCF services. There are many cases that two (or more) different clients call the server at the same and the server tries to call the remote WCF from two different threads simultaneously. We have encountered some issues, especially when the remote WCF service is down. Are we doing things correctly? is there a best pract开发者_如何学Cice for this scenario?


The best practice for most cases is this:

  • your client calls a WCF service with a "per-call" pattern
  • each request from a client gets its own, pristine server class instance that handles the request and gets disposed after it's done
  • the server class is therefore single-threaded, non-reentrant, and doesn't have to deal with any multitasking issues
  • the server class is stateless and doesn't hold on to any server resources or anything
  • any "state" or data that needs to be persisted between calls is stored in a suitable location, e.g. a database

This is by far the easiest setup and should be the best choice for at least 80% of your cases.

Check out this excellent MSDN Magazine article Discover Mighty Instance Management Techniques For Developing WCF Apps by Juwal Lovy for more background on the various options you have.


You need to be a little more specific about the types of issues you are encountering, but you might want to read up on idempotency and stateful services.

0

精彩评论

暂无评论...
验证码 换一张
取 消