Click here to Skip to main content
15,884,986 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi Guys,

It it possible to customise how visual studio 2010 generates a service reference? With something like a T4 template?

As a more specific example, I have created a Custom Data Service that aggregates a number of WCF Data Services into a single Data Service. Now I can create a service reference to this service, no problems, however, I want to add a few functions to the created proxy class - to allow Service Functions to be called. Is this possible?
Posted
Updated 17-Nov-11 4:16am
v2
Comments
Wayne Gaylard 17-Nov-11 8:30am    
What do you mean ? What result are you aiming at ?
Dave Kerr 17-Nov-11 10:17am    
I've updated the question :)

No, it isn't possible. There's a lot going on behind the wizard and you can't really customize the generated output beyond what the wizard provides (under Advanced).

You could write your own T4 to generate the necessary classes/interfaces, although it won't do automatic discovery, refreshing of the WSDL and schemas, etc., like the built-in Add Web Reference wizard does. So it would probably break every time something changed in the web service's contracts (method names, parameters, types, that sort of thing). Not really worth it, in my opinion.

Instead, consider simply writing (or generating?) a wrapper class for the MyWebServiceClient class that it outputs.
 
Share this answer
 
I think the wizard produces a service reference magic-class which is partial. So you can create another partial class of the same name in un-magicked code to add functionality to the magic. One of our applications did something similar with a WCF client magic-class.
 
Share this answer
 
Comments
Dave Kerr 17-Nov-11 11:08am    
I think this will make sense - there's nothing *wrong* with what is created by default, all I need to do is add a few functions and an event handler, so augmenting what is created with an addition to the partial class would be just right - I suppose I could even write a Visual Studio addin to allow the augmentation to be invoked via a menu option or something. Thanks for the information!
You can add as many functions/methods to the generated proxy class as you like, just be aware that everytime you regenerate the proxy using the wizard, you will have to recreate these methods. Note that it is also possible to generate the proxy class by hand if you do not want to use the wizard. Take a look at this article here on CP to give you a few options
WCF Proxy Generation Options[^]. Good luck!

Hope this helps
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900