Exposing method in datacontract class in wcf

12,859

Solution 1

Exposing Methods in a Datacontracts will not make sense.DataContracts can be applied only to the state of your objects or in otherwords member fields of the class.Methods are not states but rather they are agents of state change.

And you should not have a OperationContract inside the DataContract here is why

Can a WCF data contract contain a WCF operation contract inside it? Why?

Solution 2

As people said in Adding methods to DataContract objects for WCF

DTOs that are decorated as DataContract classes are real objects. They can have methods in them, but since a data contract describes the data which is communicated the methods are not part of the serialization process.

Share:
12,859
Selalu_Ingin_Belajar
Author by

Selalu_Ingin_Belajar

Currently mostly working in C#, and SQL. Interested in high volume transactions and how to handle it.

Updated on June 24, 2022

Comments

  • Selalu_Ingin_Belajar
    Selalu_Ingin_Belajar almost 2 years

    Possible Duplicate:
    Adding methods to DataContract objects for WCF

    is possible to expose method in data contract class?

    ex:

    [Datacontract]
    Public Class Customer
    {
        [Datamember]
        Public string ID
        {
            get;set;
        }
    
        Public void AddSession(string key, int len)
        {
    
        }
    
    }
    

    how to expose "AddSession" method at client when client consume this service?