Alternative to service reference

十年热恋 提交于 2019-12-04 10:55:36

Firstly, I believe you could easily fix your 'have to replace a lot of code' problem by creating your own proxy BatchClient which would instantiate the channel. It would work essentially the same way as the currently-used generated code does.

However before moving to the proxy-less, contract-sharing model I'd really consider why you want to move. I don't use the generated code option anymore, primarily because with familiarity of WCF it's not necessary. However I believe that the 'add service reference...' pattern is easier for WCF beginners, and it really doesn't cost you at all.

Ask yourself the following questions (or rather, explain to me):

  • What is the deployment overhead? I don't see any. The proxy that you've generated will work after deployment. You change the service address & behaviours in the configuration file.
  • Problems with source control / get latest? This should not be a problem, either. Just get latest, and use the latest. If the service has changed - and you want to take advantage of the changes - you will need to get latest version of the service contract, if you're using a shared contract file and instantiating your own channel.
  • Updating the proxy? Lack of familiarity with how the proxy works, what it is and what it does might cause this, but again it's no easier without the proxy. Really, you just right click up select 'update service reference', right?

The model you are considering is cleaner, and perhaps allows for more flexibility, but it is no simpler. If your team are having problems with maintaining the generated service proxy then I'd address those problems rather than throwing them into the deep end of WCF by removing the proxy.

There are some article that suggest to use class ClientBase to achive the same purpose.

See a) https://aturcarablog.wordpress.com/2016/08/07/alternative-way-to-consume-wcf-service/

b) http://www.codeproject.com/Articles/412363/How-to-Use-a-WCF-Service-without-Adding-a-Service

Thus, your code can be rewritten as:

using (var batchClient = new ServiceWrapper<IYourWcfService>("YourEndpointConfigurationName"))
{
    batchData = batchClient.Proxy.GetBatchData(batchNumber);
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!