Technology Corner

Home » DotNet » How to pass behaviour in WCF DataContract to client application?

How to pass behaviour in WCF DataContract to client application?

Enter your email address to follow this blog and receive notifications of new posts by email.

Join 80 other followers

Twitter updates

Error: Twitter did not respond. Please wait a few minutes and refresh this page.


RSS InfoQ Feeds

Problem Statement: You want to override ToString or any method of DataContract class and method logic should be propagate to client application.


WCF doesn’t transfer any behavior of data contract to client side by default.
I am taking here two approaches to communicate to WCF service; through proxy class generated by Visual studio and other is creating channel instance using ChannelFactory class.In later approach, DataContract should be shared between server and clients.

Say you have data contract MarketPrice.

public class MarketPrice
public string Symbol { get; set; }

public double Price { get; set; }

public override string ToString()
return string.Format("Symbol:{0} Price:{1}", Symbol, Price);

Approach 1:

Behavior of ToString() method will not propagate to client proxy. You will have to change in generated code like below:

wcf proxy

Approach 2:

You can read about how to create api or manual proxy class using channel factory here.

Service contract and Data contract are in shared library which is shared across server and client applications. Service contract implementation is still in service side.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Blogs I Follow

%d bloggers like this: