2 // WebMessageEncodingElement.cs
5 // Atsushi Enomoto <atsushi@ximian.com>
7 // Copyright (C) 2008 Novell, Inc. http://www.novell.com
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:
17 // The above copyright notice and this permission notice shall be
18 // included in all copies or substantial portions of the Software.
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.
30 using System.Collections;
31 using System.Collections.Generic;
32 using System.Collections.ObjectModel;
33 using System.ComponentModel;
34 using System.Configuration;
36 using System.Net.Security;
37 using System.Reflection;
38 using System.ServiceModel;
39 using System.ServiceModel.Channels;
40 using System.ServiceModel.Description;
41 using System.ServiceModel.Diagnostics;
42 using System.ServiceModel.Dispatcher;
43 using System.Runtime.Serialization;
47 namespace System.ServiceModel.Configuration
49 public sealed partial class WebMessageEncodingElement
50 : BindingElementExtensionElement
53 static ConfigurationPropertyCollection properties;
54 static ConfigurationProperty binding_element_type;
55 static ConfigurationProperty max_read_pool_size;
56 static ConfigurationProperty max_write_pool_size;
57 static ConfigurationProperty reader_quotas;
58 static ConfigurationProperty write_encoding;
59 static ConfigurationProperty web_content_type_mapper_type;
61 static WebMessageEncodingElement ()
63 properties = new ConfigurationPropertyCollection ();
64 binding_element_type = new ConfigurationProperty ("",
65 typeof (Type), null, new TypeConverter (), null,
66 ConfigurationPropertyOptions.None);
68 max_read_pool_size = new ConfigurationProperty ("maxReadPoolSize",
69 typeof (int), "64", null/* FIXME: get converter for int*/, null,
70 ConfigurationPropertyOptions.None);
72 max_write_pool_size = new ConfigurationProperty ("maxWritePoolSize",
73 typeof (int), "16", null/* FIXME: get converter for int*/, null,
74 ConfigurationPropertyOptions.None);
76 reader_quotas = new ConfigurationProperty ("readerQuotas",
77 typeof (XmlDictionaryReaderQuotasElement), null, null/* FIXME: get converter for XmlDictionaryReaderQuotasElement*/, null,
78 ConfigurationPropertyOptions.None);
80 write_encoding = new ConfigurationProperty ("writeEncoding",
81 typeof (Encoding), "utf-8", null/* FIXME: get converter for Encoding*/, null,
82 ConfigurationPropertyOptions.None);
84 web_content_type_mapper_type = new ConfigurationProperty ("",
85 typeof (string), null, null /* FIXME: supply */, null,
86 ConfigurationPropertyOptions.None);
88 properties.Add (binding_element_type);
89 properties.Add (max_read_pool_size);
90 properties.Add (max_write_pool_size);
91 properties.Add (reader_quotas);
92 properties.Add (write_encoding);
93 properties.Add (web_content_type_mapper_type);
96 public WebMessageEncodingElement ()
103 public override Type BindingElementType {
104 get { return (Type) base [binding_element_type]; }
107 [ConfigurationProperty ("maxReadPoolSize",
108 Options = ConfigurationPropertyOptions.None,
109 DefaultValue = "64")]
110 [IntegerValidator ( MinValue = 1,
111 MaxValue = int.MaxValue,
112 ExcludeRange = false)]
113 public int MaxReadPoolSize {
114 get { return (int) base [max_read_pool_size]; }
115 set { base [max_read_pool_size] = value; }
118 [ConfigurationProperty ("maxWritePoolSize",
119 Options = ConfigurationPropertyOptions.None,
120 DefaultValue = "16")]
121 [IntegerValidator ( MinValue = 1,
122 MaxValue = int.MaxValue,
123 ExcludeRange = false)]
124 public int MaxWritePoolSize {
125 get { return (int) base [max_write_pool_size]; }
126 set { base [max_write_pool_size] = value; }
129 [ConfigurationProperty ("readerQuotas",
130 Options = ConfigurationPropertyOptions.None)]
131 public XmlDictionaryReaderQuotasElement ReaderQuotas {
132 get { return (XmlDictionaryReaderQuotasElement) base [reader_quotas]; }
135 [ConfigurationProperty ("writeEncoding",
136 Options = ConfigurationPropertyOptions.None,
137 DefaultValue = "utf-8")]
139 public Encoding WriteEncoding {
140 get { return (Encoding) base [write_encoding]; }
141 set { base [write_encoding] = value; }
144 [ConfigurationProperty ("webContentTypeMapperType",
145 Options = ConfigurationPropertyOptions.None,
147 [StringValidator ( MinLength = 0,
148 MaxLength = int.MaxValue)]
149 public string WebContentTypeMapperType {
150 get { return (string) base [web_content_type_mapper_type]; }
151 set { base [web_content_type_mapper_type] = value; }
154 protected internal override BindingElement CreateBindingElement ()
156 var be = new WebMessageEncodingBindingElement ();
157 ApplyConfiguration (be);
161 public override void ApplyConfiguration (BindingElement bindingElement)
163 base.ApplyConfiguration (bindingElement);
164 var b = (WebMessageEncodingBindingElement) bindingElement;
165 b.ContentTypeMapper = (WebContentTypeMapper) Activator.CreateInstance (Type.GetType (WebContentTypeMapperType), true);
166 b.MaxReadPoolSize = MaxReadPoolSize;
167 b.MaxWritePoolSize = MaxWritePoolSize;
168 b.WriteEncoding = WriteEncoding;
169 ReaderQuotas.ApplyConfiguration (b.ReaderQuotas);
172 public override void CopyFrom (ServiceModelExtensionElement from)
174 base.CopyFrom (from);
175 var c = (WebMessageEncodingElement) from;
176 MaxReadPoolSize = c.MaxReadPoolSize;
177 MaxWritePoolSize = c.MaxWritePoolSize;
178 ReaderQuotas.CopyFrom (c.ReaderQuotas);
179 WriteEncoding = c.WriteEncoding;
183 static class Extensions
185 public static void ApplyConfiguration (this XmlDictionaryReaderQuotasElement e, XmlDictionaryReaderQuotas q)
187 q.MaxArrayLength = e.MaxArrayLength;
188 q.MaxBytesPerRead = e.MaxBytesPerRead;
189 q.MaxDepth = e.MaxDepth;
190 q.MaxNameTableCharCount = e.MaxNameTableCharCount;
191 q.MaxStringContentLength = e.MaxStringContentLength;
194 public static void CopyFrom (this XmlDictionaryReaderQuotasElement e, XmlDictionaryReaderQuotasElement o)
196 e.MaxArrayLength = o.MaxArrayLength;
197 e.MaxBytesPerRead = o.MaxBytesPerRead;
198 e.MaxDepth = o.MaxDepth;
199 e.MaxNameTableCharCount = o.MaxNameTableCharCount;
200 e.MaxStringContentLength = o.MaxStringContentLength;