WCF Technology Insider 24:2nd Part _ 5th Chapter _ Message: Create a message (top)

Source: Internet
Author: User

Create a message

You can select one of the many defined CreateMessage factory methods to create a message object. Most of these methods accept the contents of the SOAP message body as parameters. It is very important that the body of the message cannot be modified after it is created. The SOAP message header block, in other words, can be added and modified after the message is created. Generally speaking, the factory method of message type can be divided according to the route map of processing messages, the method of extracting data from XmlReader, the method of putting the data into the word, and generating the method that represents the soap Fault. Before we study the different classification of the factory methods, we look at some message serialization and deserialization of the context environment.

Brief description of message serialization and deserialization

Serialization and deserialization are common in distributed computing, so it is necessary to figure out what they mean when they are involved in the Messaging application system. Let's consider the basic steps for serializing and deserializing the message object. When a sending program needs to send a message to another participant, it must create an object that contains the appropriate information, and then serialize and encode it into a stream or byte, and finally send the stream or byte to the destination. When a message is received by the receiving program, it is generally a stream or byte state (the same as the data state that the sender finally processed). The receiving program must decode and deserialize the stream or byte[] as a message object, and perhaps deserialize the header or other object of the message body.

As you can see, serialization is usually related to the tasks defined by the sender, and deserialization is usually related to the recipient's task. Both the sender and the receiver create the message object, but the sender is the other object in memory to create the message object, and the receiver creates one by decoding and deserializing the stream or Byte. Once the receiving program decodes and deserializes stream or byte as a message object, it can convert the contents of the messages into one object or through multiple object conversions. This conversion, in general, is also a different form of deserialization.

Message version

Because the message object is an abstraction of the CLR to the SOAP message, and there are multiple versions of the SOAP messages used, you need to consider the SOAP message version problem of the presentation of the Messages object.

In the Message object model, versions of SOAP messages cannot be changed once they are created. Soap and ws-* specifications are constantly changing, so over time we should want these document versions to be updated. As they change, namespace and message structure changes are also understandable. To accommodate these inevitable changes, WCF provides several types of encapsulated SOAP specification and ws-* specification XML message semantics. Instances of these types are passed to the factory method to represent the version of the Message object, where most factory methods are defined to accept parameters of these types.

When a Message object is set, the System.ServiceModel.Channels.EnvelopeVersion type represents the SOAP specification followed by a message type. At the same time, System.ServiceModel. Channels.addressingversion represents the Ws-addressing specification that the message header blocks follow when the messages are serialized. At the time of WCF release, there were 2 soap old Xu Notes 2 specifications (1.1 and 1.2), Ws-addressing specification (August 2004, 1.0).

The System.ServiceModel.Channels.MessageVersion wraps the envelopeversion and addressingversion types. MessageVersion has several static properties that represent several possible combinations of envelopeversion and addressingversion. The following code shows all publicly visible members of the MessageVersion:

namespace System.ServiceModel.Channels {
Public sealed class MessageVersion {
Public addressingver Sion addressing {get;}
public static messageversion Default {get;}
Public envelopeversion Envelope {get;}
public static messageversion Soap11 {get;}
public static messageversion Soap12 {get;}
public static messageversion None {get;}
public static messageversion soap11wsaddressing10 {get;}
public static messageversion soap11wsaddressingaugust2004 {get;}
public static messageversion soap12wsaddressing10 {get;}
public static messageversion soap12wsaddressingaugust2004 {get;}     
public static MessageVersion createversion (
envelopeversion envelopeversion);
public static MessageVersion createversion (
envelopeversion envelopeversion,
addressingversion addre Ssingversion);
public override bool Equals (object obj);
public override string ToString ();
}
}

Most of the members are self-describing, and some need to be explained. In WCF version 3, Messageversion.default returns the equivalent Messageversion.soap12wsaddressing10 static property. As you can see from the name, this attribute indicates that it adheres to the SOAP 1.2 and Ws-addressing 1.0 specification. The MESSAGEVERSION.SOAP11 and MESSAGEVERSION.SOAP12 attributes are assigned to the addressingversion as Addressingversion.none and are given by the property name Envelopeversion assignment. This is useful when you want to create a program that sends SOAP messages but does not want to implement the Ws-addressing specification. As you would expect, Messageversion.none is useful for (Hackberry old XML) pox message scenarios.

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.