Search code examples
wcfvisual-studio-2010wcf-client

Customizing the message contracts when creating a WCF service reference in Visual Studio 2010


Is it possible to modify how message contracts are generated when adding a WCF service reference in Visual Studio 2010? Specifically I want the request and response objects to have properties instead of public fields.

I have no control over the WCF service itself, just the client.


Solution

  • You can't control the code in the generated proxy. If you want, you can do the proxy generation yourself, using the MetadataExchangeClient / ServiceContractGenerator classes. They'll give you a CodeDom object containing the code which you can modify (i.e., change fields into properties). There's an example of using the MEC/SCG classes in the MSDN forum post at http://social.msdn.microsoft.com/Forums/en-US/wcf/thread/14100bbb-9a73-4bcc-b513-088bb2e5ec65.