2 // TransportBindingElement.cs
5 // Atsushi Enomoto <atsushi@ximian.com>
6 // Martin Baulig <martin.baulig@xamarin.com>
8 // Copyright (C) 2005, 2007 Novell, Inc. http://www.novell.com
9 // Copyright (c) 2012 Xamarin Inc. (http://www.xamarin.com)
11 // Permission is hereby granted, free of charge, to any person obtaining
12 // a copy of this software and associated documentation files (the
13 // "Software"), to deal in the Software without restriction, including
14 // without limitation the rights to use, copy, modify, merge, publish,
15 // distribute, sublicense, and/or sell copies of the Software, and to
16 // permit persons to whom the Software is furnished to do so, subject to
17 // the following conditions:
19 // The above copyright notice and this permission notice shall be
20 // included in all copies or substantial portions of the Software.
22 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
23 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
24 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
25 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
26 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
27 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
28 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
31 using System.Collections.Generic;
33 using System.ServiceModel.Channels;
34 using System.ServiceModel.Description;
35 using System.ServiceModel.Security;
38 namespace System.ServiceModel.Channels
40 public abstract class TransportBindingElement : BindingElement
42 bool manual_addressing;
43 long max_buffer_pool_size = 0x80000;
44 long max_recv_message_size = 0x10000;
46 protected TransportBindingElement ()
50 protected TransportBindingElement (
51 TransportBindingElement other)
54 manual_addressing = other.manual_addressing;
55 max_buffer_pool_size = other.max_buffer_pool_size;
56 max_recv_message_size = other.max_recv_message_size;
59 public bool ManualAddressing {
60 get { return manual_addressing; }
61 set { manual_addressing = value; }
64 public virtual long MaxBufferPoolSize {
65 get { return max_buffer_pool_size; }
66 set { max_buffer_pool_size = value; }
69 public virtual long MaxReceivedMessageSize {
70 get { return max_recv_message_size; }
71 set { max_recv_message_size = value; }
74 public abstract string Scheme { get; }
76 public override T GetProperty<T> (BindingContext context)
78 if (typeof (T) == typeof (XmlDictionaryReaderQuotas)) {
79 XmlDictionaryReaderQuotas q =
80 new XmlDictionaryReaderQuotas ();
81 q.MaxStringContentLength = (int) MaxReceivedMessageSize;
82 return (T) (object) q;
85 if (typeof (T) == typeof (ChannelProtectionRequirements))
86 // blank one, basically it should not be used
87 // for any secure channels (
88 return (T) (object) new ChannelProtectionRequirements ();
90 if (typeof (T) == typeof (MessageVersion))
91 return (T) (object) MessageVersion.Soap12WSAddressing10;
92 return context.GetInnerProperty<T> ();
96 internal static XmlElement CreateTransportBinding (XmlElement transportToken)
98 var doc = new XmlDocument ();
99 var transportBinding = doc.CreateElement (
100 "sp", "TransportBinding", PolicyImportHelper.SecurityPolicyNS);
102 var token = doc.CreateElement (
103 "sp", "TransportToken", PolicyImportHelper.SecurityPolicyNS);
104 PolicyImportHelper.AddWrappedPolicyElement (token, transportToken);
106 var algorithmSuite = doc.CreateElement (
107 "sp", "AlgorithmSuite", PolicyImportHelper.SecurityPolicyNS);
108 var basic256 = doc.CreateElement (
109 "sp", "Basic256", PolicyImportHelper.SecurityPolicyNS);
110 PolicyImportHelper.AddWrappedPolicyElement (algorithmSuite, basic256);
112 var layout = doc.CreateElement (
113 "sp", "Layout", PolicyImportHelper.SecurityPolicyNS);
114 var strict = doc.CreateElement (
115 "sp", "Strict", PolicyImportHelper.SecurityPolicyNS);
116 PolicyImportHelper.AddWrappedPolicyElement (layout, strict);
118 PolicyImportHelper.AddWrappedPolicyElements (
119 transportBinding, token, algorithmSuite, layout);
121 return transportBinding;
124 internal static MessageEncodingBindingElement ExportAddressingPolicy (
125 PolicyConversionContext context)
127 MessageEncodingBindingElement messageEncodingElement = null;
128 foreach (var element in context.BindingElements) {
129 var check = element as MessageEncodingBindingElement;
132 messageEncodingElement = check;
136 var doc = new XmlDocument ();
137 var assertions = context.GetBindingAssertions ();
139 if (messageEncodingElement == null) {
140 assertions.Add (doc.CreateElement (
141 "wsaw", "UsingAddressing",
142 "http://www.w3.org/2006/05/addressing/wsdl"));
146 var addressing = messageEncodingElement.MessageVersion.Addressing;
147 if (addressing == AddressingVersion.WSAddressingAugust2004)
148 assertions.Add (doc.CreateElement (
149 "wsaw", "UsingAddressing",
150 "http://schemas.xmlsoap.org/ws/2004/08/addressing/policy"));
151 else if (addressing != AddressingVersion.None)
152 assertions.Add (doc.CreateElement (
153 "wsaw", "UsingAddressing",
154 "http://www.w3.org/2006/05/addressing/wsdl"));
156 return messageEncodingElement;