Shared ServiceContract Library
I had what I thought was a simple plan, create a server side (WCF) sln and a client side sln then from both of them reference the same BusinessObject (Biz) library and ServiceContract library.
What I wanted to do was use svcutil.exe to generate the client side implementation of the contract for me, so when any of the service contracts changed all I had to do was run a batch file which basically ran svcutil.
So when you do a ‘right click, add service reference’, tick the box to re-use the Biz and ServiceContract libraries, what happens is the Biz objects are not generated (good, that was expected) but the contracts ARE still generated (am I missing a simple check box somewhere??).
I don’t want the contracts to be generated as it means I now have two versions of the same contract.
If you use svcutil.exe to generated the metadata and then the proxy code, by providing a few of the right switches you get the same result as ‘add service reference’. Ok good, now that I’m using the cmd line utility I will now have the power to tailor the generated code to my exact measures….not quite. Unless I’m missing somethings obvious (which is likely I’ll admit) there is not any switch to tell svcutil to NOT generate the ServiceContracts. Yes I am using the /r: switch to provide the assembly that contains the contracts…
So I’m thinking, unless you are willing to accept and allow there to be two versions of your service contract (which actually is very common, anyone using VS right click, ‘add service reference’ will have this setup…thus the need to regularly update service reference) then really it is not possible to use svcutil.exe.
Well I hope to come back and update this in the near future with the approach we end up choosing. For now though, this post looks like a good ‘leg up’ and is certainly worth a read. I’ll be exploring that idea and a few others and report back….
Why go through the hassle, why not just use the old, ‘right click add service reference’? Well, every WCF ‘expert’ I know of says that approach is the beginners way of creating your WCF service proxies, either in their blogs or .net rocks episodes etc. It is certainly very quick but the generated code is overly verbose and as it is generated code you have less control over the way it works.