Click here to Skip to main content
15,901,666 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi team;

I have a lot confusion on data contract. I think Data contract will create according to the Service contract and Data Base Table.

For Example Let say i have service contract and i have three table product,order,customer
C#
[ServiceContract]
    public interface IMembersService
    {
        [OperationContract]
        void insertProductDetails(clsProduct objProduct);

      //What about the return type can we make it bool

        [OperationContract]
        List<clsProduct> getproductInfoByID(int id);

        [OperationContract]
        List<clsProduct> getproductInfo();



//========================================

[OperationContract]
        void insertOrderDetails(clsOrder objOrder);

      //What about the return type can we make it bool

        [OperationContract]
        List<clsOrder> getOrderInfoByID(int id);

        [OperationContract]
        List<clsOrder> getOrderInfo();



//========================================

[OperationContract]
        void insertCustomerDetails(clsOrder objOrder);

      //What about the return type can we make it bool

        [OperationContract]
        List<clsOrder> getCustomerInfoByID(int id);

        [OperationContract]
        List<clsOrder> getCustomerInfo();


    }

For this case can I create three datacontact: clsProduct, clsOrder, clsCustomer.
I mean data contact depends on their service contact and the table.

Please guide me. I want the clarity.

Thank's
Prasanta Kumar Pradhan
Posted
Updated 31-Oct-10 8:05am
v3

There are 2 main entities in WCF.

Interface and Class

Interface will represent a skeleton of the class, where class actually holds body.

So you need to apply ServiceContract on Interface itselft and OperationContract on each methods the interface is exposing.

Whenever you create an object based on the methods exposed by the interface, you need to serialize everything which is going to travel from one app-domain to another. otherwise you will get SerializationException.

so you make class itself, DataContact and each member of the class you are exposing DataMember. Now you dont need to make native data types (int, decimal, etc...) serializable. they have default DataContracts associated with them. so anything which is non-native data type i.e. class, struc, dataset, enum etc.. you have to make it DataContract.

that's why you need to tag your class MembersService with [DataContract] attribute and Property/Fields i.e. clsProduct,clsOrder,clsCustomer (please use Property instead of public variable) as [DataMember].

Also note that DataTable is not serializable so please use DataSet instead.

Please refer this MSDN Article for more information.[^]


:)
 
Share this answer
 
Ofcourse it will depend upon Service contrat..DataContract is nothing but a data type,which is used as an argument or return type in methods which are mentioned in Service contract...
 
Share this answer
 
yes it depends upon service contract
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900