Single WCF channel performance vs multiple channels

后端 未结 2 1224
情书的邮戳
情书的邮戳 2021-02-08 13:21

I have an application that reuses the same WCF channel over and over again. I keep a static reference through a factory object. I wonder if this is good pratice or that I should

相关标签:
2条回答
  • 2021-02-08 13:39

    @Darin Dimitrov

    Reuse the same proxy In many cases, you would want to reuse the same proxy. This has the best performance. It is especially true when you use security features since the initial security negotiation can have high cost.

    proxy equals channel. if you look at this blog post, you can see the following code snippet:

    ISimpleContract proxy = factory.CreateChannel();
    ((IClientChannel)proxy).Open();
    

    Furthermore, if you plan to work with sessions, you don't want to establish a new session for each request (by creating a new channel/proxy each time).

    0 讨论(0)
  • 2021-02-08 13:45

    You should use a single channel factory for all requests but different channels should be constructed for each request. Never reuse channels. They are not expensive to create and are not thread safe. What is expensive to create is the channel factory. It is thread safe and can be reused. Of course if the channel factory get into a faulted state you might need to reopen it.

    0 讨论(0)
提交回复
热议问题