2009-06-12 Bill Holmes <billholmes54@gmail.com>
[mono.git] / mcs / class / System.ServiceModel / System.ServiceModel / ServiceBehaviorAttribute.cs
1 //
2 // ServiceBehaviorAttribute.cs
3 //
4 // Author:
5 //      Atsushi Enomoto <atsushi@ximian.com>
6 //
7 // Copyright (C) 2005 Novell, Inc.  http://www.novell.com
8 //
9 // Permission is hereby granted, free of charge, to any person obtaining
10 // a copy of this software and associated documentation files (the
11 // "Software"), to deal in the Software without restriction, including
12 // without limitation the rights to use, copy, modify, merge, publish,
13 // distribute, sublicense, and/or sell copies of the Software, and to
14 // permit persons to whom the Software is furnished to do so, subject to
15 // the following conditions:
16 // 
17 // The above copyright notice and this permission notice shall be
18 // included in all copies or substantial portions of the Software.
19 // 
20 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
24 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
25 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
26 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27 //
28 using System;
29 using System.Collections.Generic;
30 using System.Collections.ObjectModel;
31 using System.Runtime.Serialization;
32 using System.Transactions;
33 using System.ServiceModel.Channels;
34 using System.ServiceModel.Description;
35 using System.ServiceModel.Dispatcher;
36
37 namespace System.ServiceModel
38 {
39         [AttributeUsage (AttributeTargets.Class)]
40         public sealed class ServiceBehaviorAttribute
41                 : Attribute, IServiceBehavior
42         {
43                 public ServiceBehaviorAttribute ()
44                 {
45                 }
46
47                 bool auto_session_shutdown, ignore_ext_data,
48                         release, inc_fault_details,
49                         use_sync_ctx, tx_close, validate_must_understand;
50                 ConcurrencyMode concurrency;
51                 IsolationLevel tx_level;
52                 string tx_timeout;
53                 InstanceContextMode context_mode = InstanceContextMode.PerCall;
54                 object singleton;
55
56                 [MonoTODO]
57                 public bool AutomaticSessionShutdown {
58                         get { return auto_session_shutdown; }
59                         set { auto_session_shutdown = value; }
60                 }
61
62                 [MonoTODO]
63                 public ConcurrencyMode ConcurrencyMode {
64                         get { return concurrency; }
65                         set { concurrency = value; }
66                 }
67
68                 [MonoTODO]
69                 public bool IgnoreExtensionDataObject {
70                         get { return ignore_ext_data; }
71                         set { ignore_ext_data = value; }
72                 }
73
74                 public InstanceContextMode InstanceContextMode {
75                         get { return context_mode; }
76                         set { context_mode = value; }
77                 }
78
79                 public bool ReleaseServiceInstanceOnTransactionComplete {
80                         get { return release; }
81                         set { release = value; }
82                 }
83
84                 [MonoTODO]
85                 public bool IncludeExceptionDetailInFaults {
86                         get { return inc_fault_details; }
87                         set { inc_fault_details = value; }
88                 }
89
90                 [MonoTODO]
91                 public bool UseSynchronizationContext {
92                         get { return use_sync_ctx; }
93                         set { use_sync_ctx = value; }
94                 }
95
96                 [MonoTODO]
97                 public bool TransactionAutoCompleteOnSessionClose {
98                         get { return tx_close; }
99                         set { tx_close = value; }
100                 }
101
102                 [MonoTODO]
103                 public IsolationLevel TransactionIsolationLevel {
104                         get { return tx_level; }
105                         set { tx_level = value; }
106                 }
107
108                 [MonoTODO]
109                 public string TransactionTimeout {
110                         get { return tx_timeout; }
111                         set {
112                                 if (value != null)
113                                         TimeSpan.Parse (value);
114                                 tx_timeout = value;
115                         }
116                 }
117
118                 [MonoTODO]
119                 public bool ValidateMustUnderstand {
120                         get { return validate_must_understand; }
121                         set { validate_must_understand = value; }
122                 }
123
124                 public object GetWellKnownSingleton ()
125                 {
126                         return singleton;
127                 }
128
129                 public void SetWellKnownSingleton (object value)
130                 {
131                         if (value == null)
132                                 throw new ArgumentNullException ("value");
133                         singleton = value;
134                 }
135
136                 [MonoTODO]
137                 void IServiceBehavior.AddBindingParameters (
138                         ServiceDescription description,
139                         ServiceHostBase serviceHostBase,
140                         Collection<ServiceEndpoint> endpoints,
141                         BindingParameterCollection parameters)
142                 {
143                 }
144
145                 [MonoTODO]
146                 void IServiceBehavior.ApplyDispatchBehavior (
147                         ServiceDescription description,
148                         ServiceHostBase serviceHostBase)
149                 {
150                         if (singleton != null && context_mode != InstanceContextMode.Single)
151                                 throw new InvalidOperationException ("When creating a Service host with a service instance, use InstanceContext.Mode.Single in the ServiceBehaviorAttribute.");
152
153                         foreach (ChannelDispatcherBase cdb in serviceHostBase.ChannelDispatchers) {
154                                 ChannelDispatcher cd = cdb as ChannelDispatcher;
155                                 if (cd == null)
156                                         continue;
157                                 if (IncludeExceptionDetailInFaults) // may be set also in ServiceDebugBehaviorAttribute
158                                         cd.IncludeExceptionDetailInFaults = true;
159                                 foreach (EndpointDispatcher ed in cd.Endpoints)
160                                         ed.DispatchRuntime.InstanceContextProvider = CreateInstanceContextProvider (serviceHostBase);
161                         }
162                 }
163
164                 IInstanceContextProvider CreateInstanceContextProvider (ServiceHostBase host)
165                 {
166                         switch (InstanceContextMode) {
167                         case InstanceContextMode.Single:
168                                 return new SingletonInstanceContextProvider (new InstanceContext (host, GetWellKnownSingleton ()));
169                         case InstanceContextMode.PerSession:
170                                 // FIXME: implement
171                                 throw new NotImplementedException ();
172                         //case InstanceContextMode.PerCall:
173                         default:
174                                 return null; // default
175                         }
176                 }
177
178                 [MonoTODO]
179                 void IServiceBehavior.Validate (
180                         ServiceDescription description,
181                         ServiceHostBase serviceHostBase)
182                 {                       
183                 }
184         }
185 }