views:

139

answers:

2

We have lots of WCF services that are only used by our own code; the code that uses them is mostly in the same solutions files that contains the services.

However they do not use a shared assembly for the contracts, so each time a data contract is change the reference to the service has to be updated by hand in all projects that use the service. (Then the code needs to be fixed up by hand)

So how do I do a simple refactoring like renamed a data item in a data contract?


Is there a way to update all references to services in a single solution with one command, rather then having to click on each reference in each project?

+1  A: 

You may have already answered you own question here.

Move your data contracts to a shared "Contracts" project, which will allow you to use the built in Refactor -> Rename option in Visual Studio to change the name, with the change being reflected in all of the projects in the solution.

Update

To clarify, the Contracts project is an internal "organisation" of your contracts. It allows many of your projects to reference one set of contracts. For example...

WCF service exposes "List GetCustomerById(int id)".

WCF service may call down to a processing layer, which might need to calculate something using another project etc. All of thes projects can use the single "Customer" definition from your Contracts project.

Any consumer of the WCF service would get the definition of the Customer via the service reference. You wouldn't share your Contracts project or send the dll for their use.

Sohnee
I have been told that we can't use a shared contract project as it give versioning problem when "patches" are done. E.g the contract assembly on both ends may have been build at different times in a customer's setup. There has been lots of problem in the past with this type of thing and .net remoting, I don't know if it is real problem with WCF, or just that people don't wish to do what the books say you should not do.
Ian Ringrose
You wouldn't supply the contracts project to an external party - they would get all of the contracts via the service. It wouldn't make any difference to the consumers of your service. You just use it organise the contracts and share them amongst your internal projects. I will add more detail to my answer...
Sohnee
+1  A: 

With your current settings you can't do it because you are regenerating the proxy each time. This is good from SOA perspective as data contract should not change very often. But if you are controlling both client and service and it is all .Net you can do as Shonee suggested. Use the /r option in svcutil to generate the proxy from the common assembly. Then you can refactor easily.

Pratik