File: MessageVersion.cs

package info (click to toggle)
mono 4.6.2.7%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 778,148 kB
  • ctags: 914,052
  • sloc: cs: 5,779,509; xml: 2,773,713; ansic: 432,645; sh: 14,749; makefile: 12,361; perl: 2,488; python: 1,434; cpp: 849; asm: 531; sql: 95; sed: 16; php: 1
file content (208 lines) | stat: -rw-r--r-- 7,432 bytes parent folder | download | duplicates (9)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
//------------------------------------------------------------
// Copyright (c) Microsoft Corporation.  All rights reserved.
//------------------------------------------------------------

namespace System.ServiceModel.Channels
{
    using System.ComponentModel;
    using System.Globalization;
    using System.Runtime;
    using System.ServiceModel.Configuration;

    [TypeConverter(typeof(MessageVersionConverter))]
    public sealed class MessageVersion
    {
        EnvelopeVersion envelope;
        AddressingVersion addressing;
        static MessageVersion none;
        static MessageVersion soap11;
        static MessageVersion soap12;
        static MessageVersion soap11Addressing10;
        static MessageVersion soap12Addressing10;
        static MessageVersion soap11Addressing200408;
        static MessageVersion soap12Addressing200408;

        static MessageVersion()
        {
            none = new MessageVersion(EnvelopeVersion.None, AddressingVersion.None);
            soap11 = new MessageVersion(EnvelopeVersion.Soap11, AddressingVersion.None);
            soap12 = new MessageVersion(EnvelopeVersion.Soap12, AddressingVersion.None);
            soap11Addressing10 = new MessageVersion(EnvelopeVersion.Soap11, AddressingVersion.WSAddressing10);
            soap12Addressing10 = new MessageVersion(EnvelopeVersion.Soap12, AddressingVersion.WSAddressing10);
            soap11Addressing200408 = new MessageVersion(EnvelopeVersion.Soap11, AddressingVersion.WSAddressingAugust2004);
            soap12Addressing200408 = new MessageVersion(EnvelopeVersion.Soap12, AddressingVersion.WSAddressingAugust2004);
        }

        MessageVersion(EnvelopeVersion envelopeVersion, AddressingVersion addressingVersion)
        {
            this.envelope = envelopeVersion;
            this.addressing = addressingVersion;
        }

        public static MessageVersion CreateVersion(EnvelopeVersion envelopeVersion)
        {
            return CreateVersion(envelopeVersion, AddressingVersion.WSAddressing10);
        }

        public static MessageVersion CreateVersion(EnvelopeVersion envelopeVersion, AddressingVersion addressingVersion)
        {
            if (envelopeVersion == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("envelopeVersion");
            }

            if (addressingVersion == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("addressingVersion");
            }

            if (envelopeVersion == EnvelopeVersion.Soap12)
            {
                if (addressingVersion == AddressingVersion.WSAddressing10)
                {
                    return soap12Addressing10;
                }
                else if (addressingVersion == AddressingVersion.WSAddressingAugust2004)
                {
                    return soap12Addressing200408;
                }
                else if (addressingVersion == AddressingVersion.None)
                {
                    return soap12;
                }
                else
                {
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgument("addressingVersion",
                        SR.GetString(SR.AddressingVersionNotSupported, addressingVersion));
                }
            }
            else if (envelopeVersion == EnvelopeVersion.Soap11)
            {
                if (addressingVersion == AddressingVersion.WSAddressing10)
                {
                    return soap11Addressing10;
                }
                else if (addressingVersion == AddressingVersion.WSAddressingAugust2004)
                {
                    return soap11Addressing200408;
                }
                else if (addressingVersion == AddressingVersion.None)
                {
                    return soap11;
                }
                else
                {
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgument("addressingVersion",
                        SR.GetString(SR.AddressingVersionNotSupported, addressingVersion));
                }
            }
            else if (envelopeVersion == EnvelopeVersion.None)
            {
                if (addressingVersion == AddressingVersion.None)
                {
                    return none;
                }
                else
                {
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgument("addressingVersion",
                        SR.GetString(SR.AddressingVersionNotSupported, addressingVersion));
                }
            }
            else
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgument("envelopeVersion",
                    SR.GetString(SR.EnvelopeVersionNotSupported, envelopeVersion));
            }
        }

        public AddressingVersion Addressing
        {
            get { return addressing; }
        }

        public static MessageVersion Default
        {
            get { return soap12Addressing10; }
        }

        public EnvelopeVersion Envelope
        {
            get { return envelope; }
        }

        public override bool Equals(object obj)
        {
            return this == obj;
        }

        public override int GetHashCode()
        {
            int code = 0;
            if (this.Envelope == EnvelopeVersion.Soap11)
                code += 1;
            if (this.Addressing == AddressingVersion.WSAddressingAugust2004)
                code += 2;
            return code;
        }

        public static MessageVersion None
        {
            get { return none; }
        }

        public static MessageVersion Soap12WSAddressing10
        {
            get { return soap12Addressing10; }
        }

        public static MessageVersion Soap11WSAddressing10
        {
            get { return soap11Addressing10; }
        }

        public static MessageVersion Soap12WSAddressingAugust2004
        {
            get { return soap12Addressing200408; }
        }

        public static MessageVersion Soap11WSAddressingAugust2004
        {
            get { return soap11Addressing200408; }
        }

        public static MessageVersion Soap11
        {
            get { return soap11; }
        }

        public static MessageVersion Soap12
        {
            get { return soap12; }
        }

        public override string ToString()
        {
            return SR.GetString(SR.MessageVersionToStringFormat, envelope.ToString(), addressing.ToString());
        }

        internal bool IsMatch(MessageVersion messageVersion)
        {
            if (messageVersion == null)
            {
                Fx.Assert("Invalid (null) messageVersion value");
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("messageVersion");
            }
            if (addressing == null)
            {
                Fx.Assert("Invalid (null) addressing value");
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(String.Format(CultureInfo.InvariantCulture, "MessageVersion.Addressing cannot be null")));
            }

            if (envelope != messageVersion.Envelope)
                return false;
            if (addressing.Namespace != messageVersion.Addressing.Namespace)
                return false;
            return true;
        }
    }
}