WCF中的数据合同(在Silverlight Apps中) [英] Data Contract In WCF (In Silverlight Apps)

查看:94
本文介绍了WCF中的数据合同(在Silverlight Apps中)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

团队;

我对数据合同有很多困惑.我认为数据合同将根据服务合同和数据库表创建.

例如,假设我有服务合同,并且我有三个表产品,订单,客户

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

[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();


    }


对于这种情况,我可以创建三个数据联系人:clsProduct,clsOrder,clsCustomer.
我的意思是数据联系取决于他们的服务联系方式和表格.

请指导我.我要清楚.

谢谢's
Prasanta Kumar Pradhan


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

推荐答案

WCF中有2个主要实体.

InterfaceClass

Interface 将代表class的骨架,其中class 实际上容纳主体.

因此,您需要在Interface本身上应用ServiceContract ,并在该接口公开的每种方法上应用OperationContract .

每当基于接口公开的方法创建对象时,都需要序列化将要从一个应用程序域移动到另一个应用程序域的所有内容.否则您将获得SerializationException.

因此您可以自己制作class DataContact 以及要公开的DataMember类的每个成员.现在,您无需使本机数据类型(int,十进制等)可序列化.它们具有与之关联的默认DataContracts.因此,任何非本地数据类型(例如,类,结构,数据集,枚举等)都必须将其设为DataContract.

这就是为什么您需要使用[DataContract]属性和属性/字段(例如,clsProduct,clsOrder,clsCustomer(请使用Property而不是public变量))将类 MembersService 标记为[DataMember].

另请注意,DataTable无法序列化,因此请改用DataSet.

有关更多信息,请参阅此MSDN文章. [
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.[^]


:)


当然,这取决于Service约束.DataContract只是一种数据类型,在Service Contract中提到的方法中用作参数或返回类型...
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...


是的,这取决于服务合同
yes it depends upon service contract


这篇关于WCF中的数据合同(在Silverlight Apps中)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆