2010-06-03 Jb Evain <jbevain@novell.com>
[mcs.git] / class / System.ServiceModel / System.ServiceModel / ServiceBehaviorAttribute.cs
blobf946e09214ac76ffa86754ede94c46474812ed42
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.
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;
37 namespace System.ServiceModel
39 [AttributeUsage (AttributeTargets.Class)]
40 public sealed class ServiceBehaviorAttribute
41 : Attribute, IServiceBehavior
43 public ServiceBehaviorAttribute ()
45 AutomaticSessionShutdown = true;
46 ConcurrencyMode = ConcurrencyMode.Single;
47 InstanceContextMode = InstanceContextMode.PerSession;
48 MaxItemsInObjectGraph = 0x10000;
49 SessionMode = SessionMode.Allowed;
50 ReleaseServiceInstanceOnTransactionComplete = true;
51 TransactionIsolationLevel = IsolationLevel.Unspecified;
52 UseSynchronizationContext = true;
53 ValidateMustUnderstand = true;
56 string tx_timeout;
57 object singleton;
59 [MonoTODO]
60 public string Name { get; set; }
61 [MonoTODO]
62 public string Namespace { get; set; }
63 [MonoTODO]
64 public string ConfigurationName { get; set; }
66 [MonoTODO]
67 public AddressFilterMode AddressFilterMode { get; set; }
69 [MonoTODO]
70 public bool AutomaticSessionShutdown { get; set; }
72 [MonoTODO]
73 public ConcurrencyMode ConcurrencyMode { get; set; }
75 [MonoTODO]
76 public bool IgnoreExtensionDataObject { get; set; }
78 public InstanceContextMode InstanceContextMode { get; set; }
80 public bool IncludeExceptionDetailInFaults { get; set; }
82 [MonoTODO]
83 public int MaxItemsInObjectGraph { get; set; }
85 [MonoTODO]
86 public bool ReleaseServiceInstanceOnTransactionComplete { get; set; }
88 [MonoTODO]
89 public SessionMode SessionMode { get; set; }
91 public bool UseSynchronizationContext { get; set; }
93 [MonoTODO]
94 public IsolationLevel TransactionIsolationLevel { get; set; }
96 [MonoTODO]
97 public bool TransactionAutoCompleteOnSessionClose { get; set; }
99 [MonoTODO]
100 public string TransactionTimeout {
101 get { return tx_timeout; }
102 set {
103 if (value != null)
104 TimeSpan.Parse (value);
105 tx_timeout = value;
109 [MonoTODO]
110 public bool ValidateMustUnderstand { get; set; }
112 public object GetWellKnownSingleton ()
114 return singleton;
117 public void SetWellKnownSingleton (object value)
119 if (value == null)
120 throw new ArgumentNullException ("value");
121 singleton = value;
124 [MonoTODO]
125 void IServiceBehavior.AddBindingParameters (
126 ServiceDescription description,
127 ServiceHostBase serviceHostBase,
128 Collection<ServiceEndpoint> endpoints,
129 BindingParameterCollection parameters)
133 [MonoTODO]
134 void IServiceBehavior.ApplyDispatchBehavior (
135 ServiceDescription description,
136 ServiceHostBase serviceHostBase)
138 if (singleton != null && InstanceContextMode != InstanceContextMode.Single)
139 throw new InvalidOperationException ("When creating a Service host with a service instance, use InstanceContextMode.Single in the ServiceBehaviorAttribute.");
141 foreach (ChannelDispatcherBase cdb in serviceHostBase.ChannelDispatchers) {
142 ChannelDispatcher cd = cdb as ChannelDispatcher;
143 if (cd == null)
144 continue;
145 if (IncludeExceptionDetailInFaults) // may be set also in ServiceDebugBehaviorAttribute
146 cd.IncludeExceptionDetailInFaults = true;
147 foreach (EndpointDispatcher ed in cd.Endpoints) {
148 if (InstanceContextMode == InstanceContextMode.Single)
149 ed.DispatchRuntime.SingletonInstanceContext = CreateSingletonInstanceContext (serviceHostBase);
150 ed.DispatchRuntime.InstanceContextProvider = CreateInstanceContextProvider (serviceHostBase, ed.DispatchRuntime);
155 InstanceContext CreateSingletonInstanceContext (ServiceHostBase host)
157 return new InstanceContext (host, GetWellKnownSingleton ());
160 IInstanceContextProvider CreateInstanceContextProvider (ServiceHostBase host, DispatchRuntime runtime)
162 switch (InstanceContextMode) {
163 case InstanceContextMode.Single:
164 return new SingletonInstanceContextProvider (runtime.SingletonInstanceContext);
165 case InstanceContextMode.PerSession:
166 return new SessionInstanceContextProvider (host);
167 //case InstanceContextMode.PerCall:
168 default:
169 return null; // default
173 [MonoTODO]
174 void IServiceBehavior.Validate (
175 ServiceDescription description,
176 ServiceHostBase serviceHostBase)