Async WCF call with ChannelFactory and CreateChannel

前端 未结 3 1696
南旧
南旧 2021-02-06 00:47

I work on project where web application hosted on web server calls WCF services hosted on the app server. Proxy for WCF calls is created by ChannelFactory and calls are made via

3条回答
  •  遥遥无期
    2021-02-06 01:48

    Unfortunately, this isn't possible and there is a pretty good reason for it. CreateChannel returns an object that implements the provided interface (IUserService in your example). This interface is not async-aware, so there is no way it could return an object with the correct methods.

    There are two possible solutions:

    1. Create your own proxy that is able to call the WCF service. This means you need to write your own proxy (or let svcutil do it for you).
    2. Make sure IUserService is an async interface that returns tasks. This is supported in WCF 4.5 and later. This is what I often use. The major drawback is that it makes your service a bit complicated and you are required to invoke the methods async (which might also be considered an advantage).

提交回复
热议问题