.netwcfchannelfactoryservice-reference

Alternative to service reference


I am trying to assist one project team to streamline their work by fixing some of the pain points.

One of the pain points they have in their code is that, they are using WCF service via service references (proxy) [i.e. "Add Service Reference" in Visua Studio 2008. This creates a lot of problem including deployment overhead, Souce Control get latest related problems of updating proxy etc.

In order to handle these and other related issues with service reference, I am looking for a good alternative to service references. I have already seen ChannelFactory and I am leaning towards that most. That seems to be a good solution altogether.

However the problem is that, there is a lot of code consuming these services like this

BatchClient client = new BatchClient(); //Batchclient is  a proxy
batchData = client.GetBatchData(batchNumber)

So if I go the ChannelFactory path, I would need to update all code piece like the above throughout the project. Because of amount of changes, the team is not very comfortable with this option.

Question I have is that, is there any other better alternative to "Add service reference" which can be used with minimal code changes? Or is there any way I could use the ChannelFactory without affecting exsting code pieces?


Solution

  • 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):

    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.