开发者

WCF Operation parameter and return type must have datacontract attribute (always)?

could some one pleas开发者_如何学Goe confirm whether I should always have a DataContract and datamember attribute for Operation Parameter and return types? e.g.

ResponseMessage getOrderDetails(RequestMessage msg)
{
  ....
}


public class ResponseMessage
{
  ...
}


public class RequestMessage
{
  ...
}


It was required only in very first version of WCF (.NET 3.0). After that default data contract serialization was introduced so you don't have to place DataContract attribute on your classes and all public properties with getter and setter will be serialized. Once you want better control over serialization you will use DataContract and DataMember attributes or you will switch to Xml serialization.


The parameter types and return types need to be either serializable or treated in a special way by WCF.

For the first case, [DataContract] and [DataMember] is only one way to make a type serializable - the post at http://blogs.msdn.com/b/sowmy/archive/2006/02/22/536747.aspx describes the serialization programming model in WCF. As Ladislav mentioned, starting with .NET 3.5 SP1 WCF introduced a default (POCO) serialization so you don't need any annotation at all.

For the second case, there are some types which are treated as special cases by WCF, such as System.IO.Stream or System.ServiceModel.Channels.Message - and you can even add more such types if you use a custom message formatter (although this is an advanced scenario and not very common).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜