[WCF]: Minor NetTcpBinding fixes.
[mono.git] / mcs / class / System.ServiceModel / System.ServiceModel.Channels / MsmqBindingElementBase.cs
1 //
2 // MsmqBindingElementBase.cs
3 //
4 // Author: Atsushi Enomoto  <atsushi@ximian.com>
5 //
6 // Copyright (C) 2007 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 using System.ServiceModel.Description;
31 using System.Xml;
32
33 namespace System.ServiceModel.Channels
34 {
35         public abstract class MsmqBindingElementBase : TransportBindingElement,
36                 ITransactedBindingElement, IPolicyExportExtension, IWsdlExportExtension
37         {
38                 Uri custom_dead_letter_queue;
39                 DeadLetterQueue dead_letter_queue = DeadLetterQueue.System;
40                 bool durable = true, exactly_once = true, tx_enabled, use_msmq_trace, use_source_journal;
41                 int max_retry_cycles = 2, receive_retry_count = 5;
42                 ReceiveErrorHandling receive_error_handling;
43                 TimeSpan retry_cycle_delay = TimeSpan.FromMinutes (30), ttl = TimeSpan.FromDays (1);
44                 MsmqTransportSecurity transport_security =
45                         new MsmqTransportSecurity ();
46
47                 internal MsmqBindingElementBase ()
48                 {
49                 }
50
51                 public Uri CustomDeadLetterQueue {
52                         get { return custom_dead_letter_queue; }
53                         set { custom_dead_letter_queue = value; }
54                 }
55
56                 public DeadLetterQueue DeadLetterQueue {
57                         get { return dead_letter_queue; }
58                         set { dead_letter_queue = value; }
59                 }
60
61                 public bool Durable {
62                         get { return durable; }
63                         set { durable = value; }
64                 }
65
66                 public bool ExactlyOnce {
67                         get { return exactly_once; }
68                         set { exactly_once = value; }
69                 }
70
71                 public int MaxRetryCycles {
72                         get { return max_retry_cycles; }
73                         set { max_retry_cycles = value; }
74                 }
75
76                 public MsmqTransportSecurity MsmqTransportSecurity {
77                         get { return transport_security; }
78                 }
79
80                 public ReceiveErrorHandling ReceiveErrorHandling {
81                         get { return receive_error_handling; }
82                         set { receive_error_handling = value; }
83                 }
84
85                 public int ReceiveRetryCount {
86                         get { return receive_retry_count; }
87                         set { receive_retry_count = value; }
88                 }
89
90                 public TimeSpan RetryCycleDelay {
91                         get { return retry_cycle_delay; }
92                         set { retry_cycle_delay = value; }
93                 }
94
95                 public TimeSpan TimeToLive {
96                         get { return ttl; }
97                         set { ttl = value; }
98                 }
99
100                 public bool TransactedReceiveEnabled {
101                         get { return tx_enabled; }
102                 }
103
104                 public bool UseMsmqTracing {
105                         get { return use_msmq_trace; }
106                         set { use_msmq_trace = value; }
107                 }
108
109                 public bool UseSourceJournal {
110                         get { return use_source_journal; }
111                         set { use_source_journal = value; }
112                 }
113
114                 public override T GetProperty<T> (BindingContext context)
115                 {
116                         if (typeof (T) is IBindingDeliveryCapabilities)
117                                 throw new NotImplementedException ();
118                         if (typeof (T) is ISecurityCapabilities)
119                                 throw new NotImplementedException ();
120                         return base.GetProperty<T> (context);
121                 }
122
123                 void IPolicyExportExtension.ExportPolicy (MetadataExporter exporter, PolicyConversionContext context)
124                 {
125                         if (exporter == null)
126                                 throw new ArgumentNullException ("exporter");
127                         if (context == null)
128                                 throw new ArgumentNullException ("context");
129
130                         PolicyAssertionCollection assertions = context.GetBindingAssertions ();
131                         XmlDocument doc = new XmlDocument ();
132
133                         assertions.Add (doc.CreateElement ("wsaw", "UsingAddressing", "http://www.w3.org/2006/05/addressing/wsdl"));
134                         assertions.Add (doc.CreateElement ("msmq", "Authenticated", "http://schemas.microsoft.com/ws/06/2004/mspolicy/msmq"));
135                         assertions.Add (doc.CreateElement ("msb", "BinaryEncoding",
136                                         "http://schemas.microsoft.com/ws/06/2004/mspolicy/netbinary1"));
137
138                         if (transport_security.MsmqAuthenticationMode == MsmqAuthenticationMode.WindowsDomain)
139                                 assertions.Add (doc.CreateElement ("msmq", "WindowsDomain",
140                                         "http://schemas.microsoft.com/ws/06/2004/mspolicy/msmq"));
141
142                         if (!durable)
143                                 assertions.Add (doc.CreateElement ("msmq", "MsmqVolatile", 
144                                         "http://schemas.microsoft.com/ws/06/2004/mspolicy/msmq"));
145
146                         if (!exactly_once)
147                                 assertions.Add (doc.CreateElement ("msmq", "MsmqBestEffort", 
148                                         "http://schemas.microsoft.com/ws/06/2004/mspolicy/msmq"));
149                 }
150
151                 [MonoTODO]
152                 void IWsdlExportExtension.ExportContract (WsdlExporter exporter, WsdlContractConversionContext context)
153                 {
154                         throw new NotImplementedException ();
155                 }
156
157                 [MonoTODO]
158                 void IWsdlExportExtension.ExportEndpoint (WsdlExporter exporter, WsdlEndpointConversionContext endpointContext)
159                 {
160                         throw new NotImplementedException ();
161                 }
162         }
163 }