WCF Learning (iv): Events in Data contracts

Source: Internet
Author: User
Tags serialization

Technical Preparation:

1.dotnet Basic development;

The basic use of 2.WCF Data contract and service contract

Content:

We all know that the data contract is also server-side to client serialization and deserialization, such serialization is similar to the ASP.net ajax access WebService. ASP.net ajax Typically, the server-side data is serialized into a Jason string passed to the foreground script, but we might want to control some data contracts filed or attributes when serializing or deserializing. This requires us to listen to some of the events that the data contract triggers when serializing and deserializing.

Events for data contracts

The data contract has four separate events in serialization and deserialization:

1.serializing event: occurs before serialization;

2.serialized event: Occurs after serialization;

3.deserializing event: Before deserialization;

4.deserialized event: After deserialization;

We can understand the four events at a glance. But how do we monitor these events, WCF provides four attribute identities to identify the specific event that one of our defined methods is to listen for identities. But when we define a method, we have to conform to the type of the delegate of these events, that is, we must have the same parameters. Let's look at the form of the definition:

1. Monitor Serializing Events:

[OnSerializing]
void OnSerializing (StreamingContext context)

2. Monitor serialized events:

[OnSerialized]
void OnSerialized (StreamingContext context)

3. Monitor deserializing events:

[OnDeserializing]
void OnDeserializing (StreamingContext context)

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.