2009-02-18 Atsushi Enomoto <atsushi@ximian.com>
[mono.git] / mcs / class / System.ServiceModel / System.ServiceModel.Channels / MessageVersion.cs
1 //
2 // System.ServiceModel.MessageVersion.cs
3 //
4 // Author: Duncan Mak (duncan@novell.com)
5 //
6 // Copyright (C) 2005 Novell, Inc (http://www.novell.com)
7 //
8 // Permission is hereby granted, free of charge, to any person obtaining
9 // a copy of this software and associated documentation files (the
10 // "Software"), to deal in the Software without restriction, including
11 // without limitation the rights to use, copy, modify, merge, publish,
12 // distribute, sublicense, and/or sell copies of the Software, and to
13 // permit persons to whom the Software is furnished to do so, subject to
14 // the following conditions:
15 // 
16 // The above copyright notice and this permission notice shall be
17 // included in all copies or substantial portions of the Software.
18 // 
19 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
20 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
21 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
22 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
23 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
24 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
25 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26 //
27
28 using System;
29 using System.ServiceModel;
30
31 namespace System.ServiceModel.Channels {
32
33         public sealed class MessageVersion
34         {
35                 EnvelopeVersion envelope;
36                 AddressingVersion addressing;
37
38                 MessageVersion (EnvelopeVersion envelope, AddressingVersion addressing)
39                 {
40                         this.envelope = envelope;
41                         this.addressing = addressing;
42                 }
43                 
44                 public static MessageVersion CreateVersion (EnvelopeVersion envelope_version)
45                 {
46                         return CreateVersion (envelope_version,
47                                 AddressingVersion.WSAddressing10);
48                 }
49
50                 public static MessageVersion CreateVersion (EnvelopeVersion envelope_version,
51                                                             AddressingVersion addressing_version)
52                 {
53                         return new MessageVersion (envelope_version, addressing_version);
54                 }
55
56                 public override bool Equals (object value)
57                 {
58                         MessageVersion other = value as MessageVersion;
59
60                         if (other == null)
61                                 return false;
62
63                         return (other.Addressing == this.Addressing) && (other.Envelope == this.Envelope);
64                 }
65
66                 public override int GetHashCode ()
67                 {
68                         return addressing.GetHashCode () + envelope.GetHashCode ();
69                 }
70
71                 public override string ToString ()
72                 {
73                         return envelope.ToString () + " " +  addressing.ToString ();
74                 }
75
76                 public AddressingVersion Addressing { 
77                         get { return addressing; }
78                 }
79
80                 public static MessageVersion Default { 
81                         get { return CreateVersion (EnvelopeVersion.Soap12); }
82                 }
83
84                 public EnvelopeVersion Envelope {
85                         get { return envelope; }
86                 }
87
88                 public static MessageVersion None { 
89                         get { return CreateVersion (EnvelopeVersion.None, AddressingVersion.None); }
90                 }
91
92                 public static MessageVersion Soap11 {
93                         get { return CreateVersion (EnvelopeVersion.Soap11, AddressingVersion.None); }
94                 }
95
96                 public static MessageVersion Soap12 {
97                         get { return CreateVersion (EnvelopeVersion.Soap12, AddressingVersion.None); }
98                 }
99
100                 public static MessageVersion Soap11WSAddressing10 {
101                         get { return CreateVersion (EnvelopeVersion.Soap11, AddressingVersion.WSAddressing10); }
102                 }
103
104                 public static MessageVersion Soap11WSAddressingAugust2004 {
105                         get { return CreateVersion (EnvelopeVersion.Soap11, AddressingVersion.WSAddressingAugust2004); }
106                 }
107
108                 public static MessageVersion Soap12WSAddressing10 {
109                         get { return CreateVersion (EnvelopeVersion.Soap12, AddressingVersion.WSAddressing10); }
110                 }
111
112                 public static MessageVersion Soap12WSAddressingAugust2004 {
113                         get { return CreateVersion (EnvelopeVersion.Soap12, AddressingVersion.WSAddressingAugust2004); }
114                 }
115         }
116 }