JakeHova
JakeHova

Reputation: 1365

Manually adding a service reference to a csproj

Setup: Over the course of the past year, I've created around 20 common WCF services that are used to handle specific tasks within my company. Developers have begun using these services readily in their applications to perform these specific tasks. The problem is that because there is currently no position in the company to enforce usage of these common services (small company and we just don't have the resources or bandwidth to enforce standards yet and I'm hoping to resolve this problem before it gets worse or unmanageable) some teams have had a tendancy to write their own services that functionally mirror what an exsisting common service already does.

To resolve this issue, I am building a basic web application that simply builds a "service layer" class library that contains the common service references (including some exposed helper methods) that perform specificed functionality. For example, if it is in the requirements that an application should allow for partial saves and for file uploading, then I would add service references to our File Uploading service and our Form Saving service to this service layer class library.

Question:
Is there a way to dynamically/programatically retrieve a WCF service reference's files (much the same way VS 2010 does when you "add service reference") and append them to a csproj file? I know how to build a generic build file (csproj), but I'm not sure what's required or what the best way to append service references to that project are.

Any help would be greatly appreciated and I thank you in advance for your time.

Upvotes: 1

Views: 1235

Answers (1)

slugster
slugster

Reputation: 49974

You do not need to generate those files in order to access a WCF service - what VS2010 is doing for you* is generating a client side mirror image of the contracts and data objects. For example, if you have a Foo defined on the server then you will get a client version of that created, and the generated proxy will deserialize to that client side version of Foo.

If you do want to generate those files, see this previous SO answer for an example of how to use svcutil.exe to generate the proxy files to a specific directory. Be aware that you really should have your contracts and data objects housed in a separate assembly, if you do then you will be able to achieve reuse between the client and the server - in other words, svcutil will not need to generate client side copies of those data objects.

*Keep in mind that this is the default behaviour of VS, it can be changed.

Upvotes: 1

Related Questions