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?
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.
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With