Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rename property names from WCF service generated model

Tags:

c#

.net

wcf

I'm currently consuming a legacy WCF service that does not conform to the naming standards from the app in development. Now when developing against a REST service, where I create the models on my own it is really easy to rename a property like so:

[DataContract]
public class SomeModel
{
    [DataMember(Name = "id")]
    public string Id { get; set; }

    // ...
}

But with the WCF service it generates the model, and I don't want to edit a generated file as all my changes would be lost when someone/-thing triggers the code generation again. So how could I achieve the same goal when consuming a WCF service?

like image 942
Mark Avatar asked Aug 21 '13 07:08

Mark


People also ask

How do I rename a WCF service?

Renaming a WCF Service Contract Change the name of the service contract. In the configuration file of the service, change the name of the service contract to the new name you have chosen, as indicated in the following example. The configuration file can be either app. config or web.

How to generate proxy for WCF service?

The WCF client proxy can be generated manually by using the Service Model Metadata Utility Tool (SvcUtil.exe) for more information see, ServiceModel Metadata Utility Tool (Svcutil.exe). The WCF client proxy can also be generated within Visual Studio using the Add Service Reference feature.

What is required by client to generate client proxy?

A metadata exchange endpoint is required to support the dynamic generation of proxy and configuration for client applications. You must explicitly enable metadata exchange by adding the endpoint and enabling the metadata exchange behavior.


1 Answers

How about adapter pattern?

this would allow you to play with your class object myClass in your application, whereas when it is being passed on to the service you can have exposedClaSs which is auto generated.

like image 50
Vinay Pandey Avatar answered Sep 20 '22 12:09

Vinay Pandey