WCF DataContract Class with Methods

This is a philosophical question rather than a technical problem.

Are there any good arguments against writing a DataContract class with methods that should only be used on the server side? Or about additional properties that are not decorated with the DataMember attribute?

For instance:

[DataContract]
public class LogEntry
{
  [DataMember]
  public string Message { get; set; }
  [DataMember]
  public string Severity { get; set; }

  public string SomeOtherProperty { get; set; }

  ...

  public void WriteToDatabase()
  {
    ...
  }
}

Not doing this seems like an awful lot of extra work that I would rather avoid, although using extension methods might make it easier. But, as a good developer, I wonder if this is bad practice.

+2
source share
3 answers

Technically, you can add an implementation in the same class with a data contract. Only related properties will be serialized.

, :

[DataContract]
public class LogEntry
{
    ...

     public void WriteToDatabase()

, , , . , , -.

, , - .

. . , , - .

, DAL, , . , dll, , , , BLL/DAL, dll.

, .

+3

, , , , WCF , DataMembers, .

, , , .

+1

,

: : // / WCF: webservice (wsdl) namedpipe

, , , -, , .

.

Please note that in the context of WCF namedpipe, you may be interested in implementing this contract only once in an assembly that is accessible to both clients and the server. In this case, you run the risk of exposing clients to server signatures.

0
source

All Articles