简体   繁体   中英

How to make override a ToString method of an WcF object?

Basically I want to override a .ToString method of a WCF object on the server side. How could this be accomplished?

Classes generated from server-side WSDL are created as partial. You can do this:

public partial YourObject{

public override string ToString()
{
  //implementation
}
}

Do you mean the data contract on the server side (where you have your services)? If so what's stopping you to just override ToString() as you do for any other classes? However as pointed out by others it wouldn't be serialized (means it wouldn't show on the client side when you add a reference to that service).

You can do what Filip suggested above to get similar behaviour on the client side. Or you can just re-use the same dll (where you defined your data contracts) when you configure your service reference on the client.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM