现在的位置: 首页 > 综合 > 正文

WCF技术内幕 第5章 (5)

2014年01月08日 ⁄ 综合 ⁄ 共 2205字 ⁄ 字号 评论关闭

5.4 创建消息

简要介绍Message的序列化和反序列化

当发送程序需要发送一个Message到另一个消息参与者时,它必须创建包含适当信息的Message对象,然后序列化和编码Message到Stream或Byte里,最后发送Stream或Byte到目的地。当接收程序收到Message时,一般来说,它还是Stream或Byte状态(和发送者最后处理的状态一样)。接收程序必须解码和反序列化stream或Byte[]为Message对象,或许还要反序列化消息头部或消息体为其他对象。

Mesage版本

            Message message1 = Message.CreateMessage(MessageVersion.Soap12WSAddressing10, null);

当设置Message对象时,System.ServiceModel.Channels.EnvelopeVersion类型代表了Message类型遵循的SOAP规范。同时,System.ServiceModel.Channels.AddressingVersion表示Message序列化时,消息头遵循WS-Addressing规范。当WCF首次发布的时候有两个SOAP规范(1.1和1.2)和两个WS-Addressing规范(2004年8月,1.0).

System.ServiceModel.Channels.MessageVersion包装了EnvelopeVersion和AddressingVersion类型。

        //
        // Summary:
        //     Gets the message version that does not use SOAP or WS-Addressing.
        //
        // Returns:
        //     The System.ServiceModel.Channels.MessageVersion that does not use SOAP or
        //     WS-Addressing.
        public static MessageVersion None { get; }
        //
        // Summary:
        //     Gets the message version using SOAP 1.1.
        //
        // Returns:
        //     The System.ServiceModel.Channels.MessageVersion using SOAP 1.1 but no version
        //     of WS-Addressing.
        public static MessageVersion Soap11 { get; }
        //
        // Summary:
        //     Gets the message version using WS-Addressing 1.0 and SOAP 1.1.
        //
        // Returns:
        //     The System.ServiceModel.Channels.MessageVersion using the version of WS-Addressing
        //     1.0 and SOAP 1.1.
        public static MessageVersion Soap11WSAddressing10 { get; }
        //
        // Summary:
        //     Gets the message version by using WS-Addressing submitted 10 August 2004
        //     and SOAP 1.1.
        //
        // Returns:
        //     The System.ServiceModel.Channels.MessageVersion using the version of WS-Addressing
        //     submitted 10 August 2004 and SOAP 1.1.
        public static MessageVersion Soap11WSAddressingAugust2004 { get; }
        //
        // Summary:
        //     Gets the message version using SOAP 1.2.
        //
        // Returns:
        //     The System.ServiceModel.Channels.MessageVersion using SOAP 1.2 but no version
        //     of WS-Addressing.
        public static MessageVersion Soap12 { get; }
        //
        // Summary:
        //     Gets the message version using WS-Addressing 1.0 and SOAP 1.2.
        //
        // Returns:
        //     The System.ServiceModel.Channels.MessageVersion using the version of WS-Addressing
        //     1.0 and SOAP 1.2.
        public static MessageVersion Soap12WSAddressing10 { get; }
        //
        // Summary:
        //     Gets the message version using WS-Addressing submitted August 2004 and SOAP
        //     1.2.
        //
        // Returns:
        //     The System.ServiceModel.Channels.MessageVersion using the version of WS-Addressing
        //     submitted 10 August 2004 and SOAP 1.2.
        public static MessageVersion Soap12WSAddressingAugust2004 { get; }

抱歉!评论已关闭.