Contract equivalence of WCF data contract

Source: Internet
Author: User

WCF data contractContractual equivalence

Lazybee

A successful communication between the client and the service does not necessarily require that both parties have the same type. Only the types of the communication parties have an equivalent data contract. IfData contractIf the following conditions are met, they are equivalent:

1 With the same name and namespace

you can use datacontractattribute name and namespace specify attributes (note that the values are case sensitive ). The default namespace is: http://schemas.datacontract.org/2004/07/Clr.Namespace . (You can also use contractnamespaceattribute to not included DeleGate declares the entire module or Assembly to modify this default value for all data contracts .) Generally, the default data contract name is the type name, but if it is a generic type, the default data contract name is composed of the following four parts:

1Generic Type name

2

3Name of the Data contract of a generic type parameter (if multiple parameters are used, they are connected in sequence)

4The hash value calculated based on the namespace of the Data contract of the generic parameter (this part is ignored if all the generic parameters are of the basic type ).

If DatacontractattributeOf Name Attribute When you specify a data contract name for a generic type, you can Name Use in attribute values {0} To specify the name of the Data contract for the first parameter of the generic type, {1} Is the second generic parameter, and so on. {#} Indicates the hash value calculated by using the data contract namespace of the generic parameter. (Note: You must have {} Oh)

2 Contains the same data contract members (note that the value is case sensitive)

The default name of a Data contract member is the type field or attribute name. You can useDatamemberattributeOfNameAttribute to set the value you want.

3 The data contract members must be in the same order.

Data contract members are sorted in sequence according to the following rules:

1Basic Data contract members

2 datamemberattributeNot includedOrderAttribute members, sorted alphabetically by the names of Data contract members

3 datamemberattributeContainsOrderAttribute Member, first followOrderIfOrderThe same attribute values are sorted alphabetically by the names of Data contract members.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.