| | | 1 | | // Licensed to the .NET Foundation under one or more agreements. |
| | | 2 | | // The .NET Foundation licenses this file to you under the MIT license. |
| | | 3 | | |
| | | 4 | | using System.Collections.Generic; |
| | | 5 | | using System.Xml; |
| | | 6 | | using CoreWCF.Dispatcher; |
| | | 7 | | using CoreWCF.Runtime; |
| | | 8 | | using WsdlNS = System.Web.Services.Description; |
| | | 9 | | |
| | | 10 | | namespace CoreWCF.Description |
| | | 11 | | { |
| | | 12 | | internal static class SoapHelper |
| | | 13 | | { |
| | 1 | 14 | | private static readonly object s_soapVersionStateKey = typeof(Dictionary<WsdlNS.Binding, EnvelopeVersion>); |
| | | 15 | | private static XmlDocument s_xmlDocument; |
| | | 16 | | |
| | | 17 | | private static XmlDocument Document |
| | | 18 | | { |
| | | 19 | | get |
| | | 20 | | { |
| | 0 | 21 | | if (s_xmlDocument == null) |
| | | 22 | | { |
| | 0 | 23 | | s_xmlDocument = new XmlDocument(); |
| | | 24 | | } |
| | | 25 | | |
| | 0 | 26 | | return s_xmlDocument; |
| | | 27 | | } |
| | | 28 | | } |
| | | 29 | | |
| | | 30 | | private static XmlAttribute CreateLocalAttribute(string name, string value) |
| | | 31 | | { |
| | 0 | 32 | | XmlAttribute attribute = Document.CreateAttribute(name); |
| | 0 | 33 | | attribute.Value = value; |
| | 0 | 34 | | return attribute; |
| | | 35 | | } |
| | | 36 | | //// ----------------------------------------------------------------------------------------------------------- |
| | | 37 | | //// Developers Note: We go through a little song and dance here to Get or Create an exsisting SoapBinding from |
| | | 38 | | //// Extensions for a number of reasons: |
| | | 39 | | //// 1. Multiple Extensions may contribute to the settings in the soap binding and so to make this work wit |
| | | 40 | | //// relying on ordering, we need the GetOrCreate method. |
| | | 41 | | //// 2. There are diffrent classes for different SOAP versions and the extensions that determines the versi |
| | | 42 | | //// also un-ordered so when we finally figure out the version we may need to recreate the BindingExten |
| | | 43 | | //// clone it. |
| | | 44 | | |
| | | 45 | | internal static WsdlNS.SoapAddressBinding GetOrCreateSoapAddressBinding(WsdlNS.Binding wsdlBinding, WsdlNS.Port |
| | | 46 | | { |
| | 32 | 47 | | if (GetSoapVersionState(wsdlBinding, exporter) == EnvelopeVersion.None) |
| | | 48 | | { |
| | 0 | 49 | | return null; |
| | | 50 | | } |
| | | 51 | | |
| | 32 | 52 | | WsdlNS.SoapAddressBinding existingSoapAddressBinding = GetSoapAddressBinding(wsdlPort); |
| | 32 | 53 | | EnvelopeVersion version = GetSoapVersion(wsdlBinding); |
| | | 54 | | |
| | 32 | 55 | | if (existingSoapAddressBinding != null) |
| | | 56 | | { |
| | 0 | 57 | | return existingSoapAddressBinding; |
| | | 58 | | } |
| | | 59 | | |
| | 32 | 60 | | WsdlNS.SoapAddressBinding soapAddressBinding = CreateSoapAddressBinding(version, wsdlPort); |
| | 32 | 61 | | return soapAddressBinding; |
| | | 62 | | } |
| | | 63 | | |
| | | 64 | | public static WsdlNS.SoapBinding GetOrCreateSoapBinding(WsdlEndpointConversionContext endpointContext, WsdlExpor |
| | | 65 | | { |
| | 32 | 66 | | if (GetSoapVersionState(endpointContext.WsdlBinding, exporter) == EnvelopeVersion.None) |
| | | 67 | | { |
| | 0 | 68 | | return null; |
| | | 69 | | } |
| | | 70 | | |
| | 32 | 71 | | WsdlNS.SoapBinding existingSoapBinding = GetSoapBinding(endpointContext); |
| | 32 | 72 | | if (existingSoapBinding != null) |
| | | 73 | | { |
| | 32 | 74 | | return existingSoapBinding; |
| | | 75 | | } |
| | | 76 | | |
| | 0 | 77 | | EnvelopeVersion version = GetSoapVersion(endpointContext.WsdlBinding); |
| | 0 | 78 | | WsdlNS.SoapBinding soapBinding = CreateSoapBinding(version, endpointContext.WsdlBinding); |
| | 0 | 79 | | return soapBinding; |
| | | 80 | | } |
| | | 81 | | |
| | | 82 | | internal static WsdlNS.SoapOperationBinding GetOrCreateSoapOperationBinding(WsdlEndpointConversionContext endpoi |
| | | 83 | | { |
| | 159 | 84 | | if (GetSoapVersionState(endpointContext.WsdlBinding, exporter) == EnvelopeVersion.None) |
| | | 85 | | { |
| | 0 | 86 | | return null; |
| | | 87 | | } |
| | | 88 | | |
| | 159 | 89 | | WsdlNS.SoapOperationBinding existingSoapOperationBinding = GetSoapOperationBinding(endpointContext, operatio |
| | 159 | 90 | | WsdlNS.OperationBinding wsdlOperationBinding = endpointContext.GetOperationBinding(operation); |
| | 159 | 91 | | EnvelopeVersion version = GetSoapVersion(endpointContext.WsdlBinding); |
| | | 92 | | |
| | 159 | 93 | | if (existingSoapOperationBinding != null) |
| | | 94 | | { |
| | 159 | 95 | | return existingSoapOperationBinding; |
| | | 96 | | } |
| | | 97 | | |
| | 0 | 98 | | WsdlNS.SoapOperationBinding soapOperationBinding = CreateSoapOperationBinding(version, wsdlOperationBinding) |
| | 0 | 99 | | return soapOperationBinding; |
| | | 100 | | } |
| | | 101 | | |
| | | 102 | | internal static WsdlNS.SoapBodyBinding GetOrCreateSoapBodyBinding(WsdlEndpointConversionContext endpointContext, |
| | | 103 | | { |
| | 318 | 104 | | if (GetSoapVersionState(endpointContext.WsdlBinding, exporter) == EnvelopeVersion.None) |
| | | 105 | | { |
| | 0 | 106 | | return null; |
| | | 107 | | } |
| | | 108 | | |
| | 318 | 109 | | WsdlNS.SoapBodyBinding existingSoapBodyBinding = GetSoapBodyBinding(endpointContext, wsdlMessageBinding); |
| | 318 | 110 | | EnvelopeVersion version = GetSoapVersion(endpointContext.WsdlBinding); |
| | | 111 | | |
| | 318 | 112 | | if (existingSoapBodyBinding != null) |
| | | 113 | | { |
| | 0 | 114 | | return existingSoapBodyBinding; |
| | | 115 | | } |
| | | 116 | | |
| | 318 | 117 | | WsdlNS.SoapBodyBinding soapBodyBinding = CreateSoapBodyBinding(version, wsdlMessageBinding); |
| | 318 | 118 | | return soapBodyBinding; |
| | | 119 | | } |
| | | 120 | | |
| | | 121 | | internal static WsdlNS.SoapHeaderBinding CreateSoapHeaderBinding(WsdlEndpointConversionContext endpointContext, |
| | | 122 | | { |
| | 0 | 123 | | EnvelopeVersion version = GetSoapVersion(endpointContext.WsdlBinding); |
| | | 124 | | |
| | 0 | 125 | | WsdlNS.SoapHeaderBinding soapHeaderBinding = CreateSoapHeaderBinding(version, wsdlMessageBinding); |
| | 0 | 126 | | return soapHeaderBinding; |
| | | 127 | | } |
| | | 128 | | |
| | | 129 | | internal static void CreateSoapFaultBinding(string name, WsdlEndpointConversionContext endpointContext, WsdlNS.F |
| | | 130 | | { |
| | 0 | 131 | | EnvelopeVersion version = GetSoapVersion(endpointContext.WsdlBinding); |
| | 0 | 132 | | XmlElement fault = CreateSoapFaultBinding(version); |
| | 0 | 133 | | fault.Attributes.Append(CreateLocalAttribute("name", name)); |
| | 0 | 134 | | fault.Attributes.Append(CreateLocalAttribute("use", isEncoded ? "encoded" : "literal")); |
| | 0 | 135 | | wsdlFaultBinding.Extensions.Add(fault); |
| | 0 | 136 | | } |
| | | 137 | | |
| | | 138 | | internal static void SetSoapVersion(WsdlEndpointConversionContext endpointContext, WsdlExporter exporter, Envelo |
| | | 139 | | { |
| | 32 | 140 | | SetSoapVersionState(endpointContext.WsdlBinding, exporter, version); |
| | | 141 | | |
| | | 142 | | //Convert all SOAP extensions to the right version. |
| | 32 | 143 | | if (endpointContext.WsdlPort != null) |
| | | 144 | | { |
| | 32 | 145 | | SoapConverter.ConvertExtensions(endpointContext.WsdlPort.Extensions, version, SoapConverter.ConvertSoapA |
| | | 146 | | } |
| | | 147 | | |
| | 32 | 148 | | SoapConverter.ConvertExtensions(endpointContext.WsdlBinding.Extensions, version, SoapConverter.ConvertSoapBi |
| | | 149 | | |
| | 382 | 150 | | foreach (WsdlNS.OperationBinding operationBinding in endpointContext.WsdlBinding.Operations) |
| | | 151 | | { |
| | 159 | 152 | | SoapConverter.ConvertExtensions(operationBinding.Extensions, version, SoapConverter.ConvertSoapOperation |
| | | 153 | | |
| | | 154 | | //Messages |
| | | 155 | | { |
| | 159 | 156 | | if (operationBinding.Input != null) |
| | | 157 | | { |
| | 159 | 158 | | SoapConverter.ConvertExtensions(operationBinding.Input.Extensions, version, SoapConverter.Conver |
| | | 159 | | } |
| | | 160 | | |
| | 159 | 161 | | if (operationBinding.Output != null) |
| | | 162 | | { |
| | 159 | 163 | | SoapConverter.ConvertExtensions(operationBinding.Output.Extensions, version, SoapConverter.Conve |
| | | 164 | | } |
| | | 165 | | |
| | 318 | 166 | | foreach (WsdlNS.MessageBinding faultBinding in operationBinding.Faults) |
| | | 167 | | { |
| | 0 | 168 | | SoapConverter.ConvertExtensions(faultBinding.Extensions, version, SoapConverter.ConvertSoapMessa |
| | | 169 | | } |
| | | 170 | | } |
| | | 171 | | } |
| | | 172 | | |
| | 32 | 173 | | } |
| | | 174 | | |
| | | 175 | | internal static EnvelopeVersion GetSoapVersion(WsdlNS.Binding wsdlBinding) |
| | | 176 | | { |
| | 2532 | 177 | | foreach (object o in wsdlBinding.Extensions) |
| | | 178 | | { |
| | 916 | 179 | | if (o is WsdlNS.SoapBinding) |
| | | 180 | | { |
| | 636 | 181 | | return o is WsdlNS.Soap12Binding ? EnvelopeVersion.Soap12 : EnvelopeVersion.Soap11; |
| | | 182 | | } |
| | | 183 | | } |
| | | 184 | | |
| | 32 | 185 | | return EnvelopeVersion.Soap12; |
| | 636 | 186 | | } |
| | | 187 | | |
| | | 188 | | private static void SetSoapVersionState(WsdlNS.Binding wsdlBinding, WsdlExporter exporter, EnvelopeVersion versi |
| | | 189 | | { |
| | 32 | 190 | | object versions = null; |
| | | 191 | | |
| | 32 | 192 | | if (!exporter.State.TryGetValue(s_soapVersionStateKey, out versions)) |
| | | 193 | | { |
| | 24 | 194 | | versions = new Dictionary<WsdlNS.Binding, EnvelopeVersion>(); |
| | 24 | 195 | | exporter.State[s_soapVersionStateKey] = versions; |
| | | 196 | | } |
| | | 197 | | |
| | 32 | 198 | | ((Dictionary<WsdlNS.Binding, EnvelopeVersion>)versions)[wsdlBinding] = version; |
| | 32 | 199 | | } |
| | | 200 | | |
| | | 201 | | private static EnvelopeVersion GetSoapVersionState(WsdlNS.Binding wsdlBinding, WsdlExporter exporter) |
| | | 202 | | { |
| | | 203 | | object versions; |
| | 541 | 204 | | if (exporter.State.TryGetValue(s_soapVersionStateKey, out versions)) |
| | | 205 | | { |
| | 517 | 206 | | if (versions != null && ((Dictionary<WsdlNS.Binding, EnvelopeVersion>)versions).ContainsKey(wsdlBinding) |
| | | 207 | | { |
| | 509 | 208 | | return ((Dictionary<WsdlNS.Binding, EnvelopeVersion>)versions)[wsdlBinding]; |
| | | 209 | | } |
| | | 210 | | } |
| | | 211 | | |
| | 32 | 212 | | return null; |
| | | 213 | | } |
| | | 214 | | |
| | | 215 | | private static class SoapConverter |
| | | 216 | | { |
| | | 217 | | // This could be simplified if we used generics. |
| | | 218 | | internal static void ConvertExtensions(WsdlNS.ServiceDescriptionFormatExtensionCollection extensions, Envelo |
| | | 219 | | { |
| | 541 | 220 | | bool foundOne = false; |
| | 1174 | 221 | | for (int i = extensions.Count - 1; i >= 0; i--) |
| | | 222 | | { |
| | 46 | 223 | | object o = extensions[i]; |
| | 46 | 224 | | if (conversionMethod(ref o, version)) |
| | | 225 | | { |
| | 32 | 226 | | if (o == null) |
| | | 227 | | { |
| | 0 | 228 | | extensions.Remove(extensions[i]); |
| | | 229 | | } |
| | | 230 | | else |
| | | 231 | | { |
| | 32 | 232 | | extensions[i] = o; |
| | | 233 | | } |
| | | 234 | | |
| | 32 | 235 | | foundOne = true; |
| | | 236 | | } |
| | | 237 | | } |
| | | 238 | | |
| | 541 | 239 | | if (!foundOne) |
| | | 240 | | { |
| | 509 | 241 | | object o = null; |
| | 509 | 242 | | conversionMethod(ref o, version); |
| | 509 | 243 | | if (o != null) |
| | | 244 | | { |
| | 191 | 245 | | extensions.Add(o); |
| | | 246 | | } |
| | | 247 | | } |
| | 541 | 248 | | } |
| | | 249 | | |
| | | 250 | | // This is the delegate implemented by the 4 methods below. It is expected to: |
| | | 251 | | // If given a null reference for src, a new instance of the extension can be set. |
| | | 252 | | internal delegate bool ConvertExtension(ref object src, EnvelopeVersion version); |
| | | 253 | | |
| | | 254 | | internal static bool ConvertSoapBinding(ref object src, EnvelopeVersion version) |
| | | 255 | | { |
| | 46 | 256 | | WsdlNS.SoapBinding binding = src as WsdlNS.SoapBinding; |
| | | 257 | | |
| | 46 | 258 | | if (src != null) |
| | | 259 | | { |
| | 14 | 260 | | if (binding == null) |
| | | 261 | | { |
| | 14 | 262 | | return false; // not a soap object |
| | | 263 | | } |
| | 0 | 264 | | else if (GetBindingVersion<WsdlNS.Soap12Binding>(src) == version) |
| | | 265 | | { |
| | 0 | 266 | | return true; // matched but same version; no change |
| | | 267 | | } |
| | | 268 | | } |
| | | 269 | | |
| | 32 | 270 | | if (version == EnvelopeVersion.None) |
| | | 271 | | { |
| | 0 | 272 | | src = null; |
| | 0 | 273 | | return true; |
| | | 274 | | } |
| | | 275 | | |
| | 32 | 276 | | WsdlNS.SoapBinding dest = version == EnvelopeVersion.Soap12 ? new WsdlNS.Soap12Binding() : new WsdlNS.So |
| | 32 | 277 | | if (binding != null) |
| | | 278 | | { |
| | 0 | 279 | | dest.Required = binding.Required; |
| | 0 | 280 | | dest.Style = binding.Style; |
| | 0 | 281 | | dest.Transport = binding.Transport; |
| | | 282 | | } |
| | | 283 | | |
| | 32 | 284 | | src = dest; |
| | 32 | 285 | | return true; |
| | | 286 | | } |
| | | 287 | | |
| | | 288 | | internal static bool ConvertSoapAddressBinding(ref object src, EnvelopeVersion version) |
| | | 289 | | { |
| | 32 | 290 | | WsdlNS.SoapAddressBinding binding = src as WsdlNS.SoapAddressBinding; |
| | | 291 | | |
| | 32 | 292 | | if (src != null) |
| | | 293 | | { |
| | 32 | 294 | | if (binding == null) |
| | | 295 | | { |
| | 0 | 296 | | return false; // no match |
| | | 297 | | } |
| | 32 | 298 | | else if (GetBindingVersion<WsdlNS.Soap12AddressBinding>(src) == version) |
| | | 299 | | { |
| | 11 | 300 | | return true; // matched but same version; no change |
| | | 301 | | } |
| | | 302 | | } |
| | | 303 | | |
| | 21 | 304 | | if (version == EnvelopeVersion.None) |
| | | 305 | | { |
| | 0 | 306 | | src = null; |
| | 0 | 307 | | return true; |
| | | 308 | | } |
| | | 309 | | |
| | 21 | 310 | | WsdlNS.SoapAddressBinding dest = version == EnvelopeVersion.Soap12 ? new WsdlNS.Soap12AddressBinding() : |
| | 21 | 311 | | if (binding != null) |
| | | 312 | | { |
| | 21 | 313 | | dest.Required = binding.Required; |
| | 21 | 314 | | dest.Location = binding.Location; |
| | | 315 | | } |
| | | 316 | | |
| | 21 | 317 | | src = dest; |
| | 21 | 318 | | return true; |
| | | 319 | | } |
| | | 320 | | |
| | | 321 | | |
| | | 322 | | // // returns true if src is an expected type; updates src in place; should handle null |
| | | 323 | | internal static bool ConvertSoapOperationBinding(ref object src, EnvelopeVersion version) |
| | | 324 | | { |
| | 159 | 325 | | WsdlNS.SoapOperationBinding binding = src as WsdlNS.SoapOperationBinding; |
| | | 326 | | |
| | 159 | 327 | | if (src != null) |
| | | 328 | | { |
| | 0 | 329 | | if (binding == null) |
| | | 330 | | { |
| | 0 | 331 | | return false; // no match |
| | | 332 | | } |
| | 0 | 333 | | else if (GetBindingVersion<WsdlNS.Soap12OperationBinding>(src) == version) |
| | | 334 | | { |
| | 0 | 335 | | return true; // matched but same version |
| | | 336 | | } |
| | | 337 | | } |
| | | 338 | | |
| | 159 | 339 | | if (version == EnvelopeVersion.None) |
| | | 340 | | { |
| | 0 | 341 | | src = null; |
| | 0 | 342 | | return true; |
| | | 343 | | } |
| | | 344 | | |
| | 159 | 345 | | WsdlNS.SoapOperationBinding dest = version == EnvelopeVersion.Soap12 ? new WsdlNS.Soap12OperationBinding |
| | 159 | 346 | | if (src != null) |
| | | 347 | | { |
| | 0 | 348 | | dest.Required = binding.Required; |
| | 0 | 349 | | dest.Style = binding.Style; |
| | 0 | 350 | | dest.SoapAction = binding.SoapAction; |
| | | 351 | | } |
| | | 352 | | |
| | 159 | 353 | | src = dest; |
| | 159 | 354 | | return true; |
| | | 355 | | } |
| | | 356 | | |
| | | 357 | | internal static bool ConvertSoapMessageBinding(ref object src, EnvelopeVersion version) |
| | | 358 | | { |
| | 318 | 359 | | WsdlNS.SoapBodyBinding body = src as WsdlNS.SoapBodyBinding; |
| | 318 | 360 | | if (body != null) |
| | | 361 | | { |
| | 0 | 362 | | src = ConvertSoapBodyBinding(body, version); |
| | 0 | 363 | | return true; |
| | | 364 | | } |
| | | 365 | | |
| | 318 | 366 | | WsdlNS.SoapHeaderBinding header = src as WsdlNS.SoapHeaderBinding; |
| | 318 | 367 | | if (header != null) |
| | | 368 | | { |
| | 0 | 369 | | src = ConvertSoapHeaderBinding(header, version); |
| | 0 | 370 | | return true; |
| | | 371 | | } |
| | | 372 | | |
| | 318 | 373 | | WsdlNS.SoapFaultBinding fault = src as WsdlNS.SoapFaultBinding; |
| | 318 | 374 | | if (fault != null) |
| | | 375 | | { |
| | 0 | 376 | | src = ConvertSoapFaultBinding(fault, version); |
| | 0 | 377 | | return true; |
| | | 378 | | } |
| | | 379 | | |
| | 318 | 380 | | XmlElement element = src as XmlElement; |
| | 318 | 381 | | if (element != null) |
| | | 382 | | { |
| | 0 | 383 | | if (IsSoapFaultBinding(element)) |
| | | 384 | | { |
| | 0 | 385 | | src = ConvertSoapFaultBinding(element, version); |
| | 0 | 386 | | return true; |
| | | 387 | | } |
| | | 388 | | } |
| | | 389 | | |
| | 318 | 390 | | return src == null; // "match" only if nothing passed in |
| | | 391 | | } |
| | | 392 | | |
| | | 393 | | private static WsdlNS.SoapBodyBinding ConvertSoapBodyBinding(WsdlNS.SoapBodyBinding src, EnvelopeVersion ver |
| | | 394 | | { |
| | 0 | 395 | | if (version == EnvelopeVersion.None) |
| | | 396 | | { |
| | 0 | 397 | | return null; |
| | | 398 | | } |
| | | 399 | | |
| | 0 | 400 | | EnvelopeVersion srcVersion = GetBindingVersion<WsdlNS.Soap12BodyBinding>(src); |
| | 0 | 401 | | if (srcVersion == version) |
| | | 402 | | { |
| | 0 | 403 | | return src; |
| | | 404 | | } |
| | | 405 | | |
| | 0 | 406 | | WsdlNS.SoapBodyBinding dest = version == EnvelopeVersion.Soap12 ? new WsdlNS.Soap12BodyBinding() : new W |
| | 0 | 407 | | if (src != null) |
| | | 408 | | { |
| | 0 | 409 | | if (XmlSerializerOperationFormatter.GetEncoding(srcVersion) == src.Encoding) |
| | | 410 | | { |
| | 0 | 411 | | dest.Encoding = XmlSerializerOperationFormatter.GetEncoding(version); |
| | | 412 | | } |
| | | 413 | | |
| | 0 | 414 | | dest.Encoding = XmlSerializerOperationFormatter.GetEncoding(version); |
| | 0 | 415 | | dest.Namespace = src.Namespace; |
| | 0 | 416 | | dest.Parts = src.Parts; |
| | 0 | 417 | | dest.PartsString = src.PartsString; |
| | 0 | 418 | | dest.Use = src.Use; |
| | 0 | 419 | | dest.Required = src.Required; |
| | | 420 | | } |
| | | 421 | | |
| | 0 | 422 | | return dest; |
| | | 423 | | } |
| | | 424 | | |
| | | 425 | | private static XmlElement ConvertSoapFaultBinding(XmlElement src, EnvelopeVersion version) |
| | | 426 | | { |
| | 0 | 427 | | if (src == null) |
| | | 428 | | { |
| | 0 | 429 | | return null; |
| | | 430 | | } |
| | | 431 | | |
| | 0 | 432 | | if (version == EnvelopeVersion.Soap12) |
| | | 433 | | { |
| | 0 | 434 | | if (src.NamespaceURI == WsdlNS.Soap12Binding.Namespace) |
| | | 435 | | { |
| | 0 | 436 | | return src; |
| | | 437 | | } |
| | | 438 | | } |
| | 0 | 439 | | else if (version == EnvelopeVersion.Soap11) |
| | | 440 | | { |
| | 0 | 441 | | if (src.NamespaceURI == WsdlNS.SoapBinding.Namespace) |
| | | 442 | | { |
| | 0 | 443 | | return src; |
| | | 444 | | } |
| | | 445 | | } |
| | | 446 | | else |
| | | 447 | | { |
| | 0 | 448 | | return null; |
| | | 449 | | } |
| | | 450 | | |
| | 0 | 451 | | XmlElement dest = CreateSoapFaultBinding(version); |
| | 0 | 452 | | if (src.HasAttributes) |
| | | 453 | | { |
| | 0 | 454 | | foreach (XmlAttribute attribute in src.Attributes) |
| | | 455 | | { |
| | 0 | 456 | | dest.SetAttribute(attribute.Name, attribute.Value); |
| | | 457 | | } |
| | | 458 | | } |
| | | 459 | | |
| | 0 | 460 | | return dest; |
| | | 461 | | } |
| | | 462 | | |
| | | 463 | | private static WsdlNS.SoapFaultBinding ConvertSoapFaultBinding(WsdlNS.SoapFaultBinding src, EnvelopeVersion |
| | | 464 | | { |
| | 0 | 465 | | if (version == EnvelopeVersion.None) |
| | | 466 | | { |
| | 0 | 467 | | return null; |
| | | 468 | | } |
| | | 469 | | |
| | 0 | 470 | | if (GetBindingVersion<WsdlNS.Soap12FaultBinding>(src) == version) |
| | | 471 | | { |
| | 0 | 472 | | return src; |
| | | 473 | | } |
| | | 474 | | |
| | 0 | 475 | | WsdlNS.SoapFaultBinding dest = version == EnvelopeVersion.Soap12 ? new WsdlNS.Soap12FaultBinding() : new |
| | 0 | 476 | | if (src != null) |
| | | 477 | | { |
| | 0 | 478 | | dest.Encoding = src.Encoding; |
| | 0 | 479 | | dest.Name = src.Name; |
| | 0 | 480 | | dest.Namespace = src.Namespace; |
| | 0 | 481 | | dest.Use = src.Use; |
| | 0 | 482 | | dest.Required = src.Required; |
| | | 483 | | } |
| | | 484 | | |
| | 0 | 485 | | return dest; |
| | | 486 | | } |
| | | 487 | | |
| | | 488 | | private static WsdlNS.SoapHeaderBinding ConvertSoapHeaderBinding(WsdlNS.SoapHeaderBinding src, EnvelopeVersi |
| | | 489 | | { |
| | 0 | 490 | | if (version == EnvelopeVersion.None) |
| | | 491 | | { |
| | 0 | 492 | | return null; |
| | | 493 | | } |
| | | 494 | | |
| | 0 | 495 | | if (GetBindingVersion<WsdlNS.Soap12HeaderBinding>(src) == version) |
| | | 496 | | { |
| | 0 | 497 | | return src; |
| | | 498 | | } |
| | | 499 | | |
| | 0 | 500 | | WsdlNS.SoapHeaderBinding dest = version == EnvelopeVersion.Soap12 ? new WsdlNS.Soap12HeaderBinding() : n |
| | 0 | 501 | | if (src != null) |
| | | 502 | | { |
| | 0 | 503 | | dest.Fault = src.Fault; |
| | 0 | 504 | | dest.MapToProperty = src.MapToProperty; |
| | 0 | 505 | | dest.Message = src.Message; |
| | 0 | 506 | | dest.Part = src.Part; |
| | 0 | 507 | | dest.Encoding = src.Encoding; |
| | 0 | 508 | | dest.Namespace = src.Namespace; |
| | 0 | 509 | | dest.Use = src.Use; |
| | 0 | 510 | | dest.Required = src.Required; |
| | | 511 | | } |
| | | 512 | | |
| | 0 | 513 | | return dest; |
| | | 514 | | } |
| | | 515 | | |
| | | 516 | | internal static EnvelopeVersion GetBindingVersion<T12>(object src) |
| | | 517 | | { |
| | 32 | 518 | | return src is T12 ? EnvelopeVersion.Soap12 : EnvelopeVersion.Soap11; |
| | | 519 | | } |
| | | 520 | | } |
| | | 521 | | |
| | | 522 | | private static WsdlNS.SoapAddressBinding CreateSoapAddressBinding(EnvelopeVersion version, WsdlNS.Port wsdlPort) |
| | | 523 | | { |
| | 32 | 524 | | WsdlNS.SoapAddressBinding soapAddressBinding = null; |
| | | 525 | | |
| | 32 | 526 | | if (version == EnvelopeVersion.Soap12) |
| | | 527 | | { |
| | 32 | 528 | | soapAddressBinding = new WsdlNS.Soap12AddressBinding(); |
| | | 529 | | } |
| | 0 | 530 | | else if (version == EnvelopeVersion.Soap11) |
| | | 531 | | { |
| | 0 | 532 | | soapAddressBinding = new WsdlNS.SoapAddressBinding(); |
| | | 533 | | } |
| | | 534 | | |
| | | 535 | | Fx.Assert(soapAddressBinding != null, "EnvelopeVersion is not recognized. Please update the SoapHelper class |
| | | 536 | | |
| | 32 | 537 | | wsdlPort.Extensions.Add(soapAddressBinding); |
| | 32 | 538 | | return soapAddressBinding; |
| | | 539 | | } |
| | | 540 | | |
| | | 541 | | internal static WsdlNS.SoapBinding CreateSoapBinding(EnvelopeVersion version, WsdlNS.Binding wsdlBinding) |
| | | 542 | | { |
| | 0 | 543 | | WsdlNS.SoapBinding soapBinding = null; |
| | | 544 | | |
| | 0 | 545 | | if (version == EnvelopeVersion.Soap12) |
| | | 546 | | { |
| | 0 | 547 | | soapBinding = new WsdlNS.Soap12Binding(); |
| | | 548 | | } |
| | 0 | 549 | | else if (version == EnvelopeVersion.Soap11) |
| | | 550 | | { |
| | 0 | 551 | | soapBinding = new WsdlNS.SoapBinding(); |
| | | 552 | | } |
| | | 553 | | |
| | | 554 | | Fx.Assert(soapBinding != null, "EnvelopeVersion is not recognized. Please update the SoapHelper class"); |
| | | 555 | | |
| | 0 | 556 | | wsdlBinding.Extensions.Add(soapBinding); |
| | 0 | 557 | | return soapBinding; |
| | | 558 | | } |
| | | 559 | | |
| | | 560 | | private static WsdlNS.SoapOperationBinding CreateSoapOperationBinding(EnvelopeVersion version, WsdlNS.OperationB |
| | | 561 | | { |
| | 0 | 562 | | WsdlNS.SoapOperationBinding soapOperationBinding = null; |
| | | 563 | | |
| | 0 | 564 | | if (version == EnvelopeVersion.Soap12) |
| | | 565 | | { |
| | 0 | 566 | | soapOperationBinding = new WsdlNS.Soap12OperationBinding(); |
| | | 567 | | } |
| | 0 | 568 | | else if (version == EnvelopeVersion.Soap11) |
| | | 569 | | { |
| | 0 | 570 | | soapOperationBinding = new WsdlNS.SoapOperationBinding(); |
| | | 571 | | } |
| | | 572 | | |
| | | 573 | | Fx.Assert(soapOperationBinding != null, "EnvelopeVersion is not recognized. Please update the SoapHelper cla |
| | | 574 | | |
| | 0 | 575 | | wsdlOperationBinding.Extensions.Add(soapOperationBinding); |
| | 0 | 576 | | return soapOperationBinding; |
| | | 577 | | } |
| | | 578 | | |
| | | 579 | | private static WsdlNS.SoapBodyBinding CreateSoapBodyBinding(EnvelopeVersion version, WsdlNS.MessageBinding wsdlM |
| | | 580 | | { |
| | 318 | 581 | | WsdlNS.SoapBodyBinding soapBodyBinding = null; |
| | | 582 | | |
| | 318 | 583 | | if (version == EnvelopeVersion.Soap12) |
| | | 584 | | { |
| | 110 | 585 | | soapBodyBinding = new WsdlNS.Soap12BodyBinding(); |
| | | 586 | | } |
| | 208 | 587 | | else if (version == EnvelopeVersion.Soap11) |
| | | 588 | | { |
| | 208 | 589 | | soapBodyBinding = new WsdlNS.SoapBodyBinding(); |
| | | 590 | | } |
| | | 591 | | |
| | | 592 | | Fx.Assert(soapBodyBinding != null, "EnvelopeVersion is not recognized. Please update the SoapHelper class"); |
| | | 593 | | |
| | 318 | 594 | | wsdlMessageBinding.Extensions.Add(soapBodyBinding); |
| | 318 | 595 | | return soapBodyBinding; |
| | | 596 | | } |
| | | 597 | | |
| | | 598 | | private static WsdlNS.SoapHeaderBinding CreateSoapHeaderBinding(EnvelopeVersion version, WsdlNS.MessageBinding w |
| | | 599 | | { |
| | 0 | 600 | | WsdlNS.SoapHeaderBinding soapHeaderBinding = null; |
| | | 601 | | |
| | 0 | 602 | | if (version == EnvelopeVersion.Soap12) |
| | | 603 | | { |
| | 0 | 604 | | soapHeaderBinding = new WsdlNS.Soap12HeaderBinding(); |
| | | 605 | | } |
| | 0 | 606 | | else if (version == EnvelopeVersion.Soap11) |
| | | 607 | | { |
| | 0 | 608 | | soapHeaderBinding = new WsdlNS.SoapHeaderBinding(); |
| | | 609 | | } |
| | | 610 | | |
| | | 611 | | Fx.Assert(soapHeaderBinding != null, "EnvelopeVersion is not recognized. Please update the SoapHelper class" |
| | | 612 | | |
| | 0 | 613 | | wsdlMessageBinding.Extensions.Add(soapHeaderBinding); |
| | 0 | 614 | | return soapHeaderBinding; |
| | | 615 | | } |
| | | 616 | | |
| | | 617 | | private static XmlElement CreateSoapFaultBinding(EnvelopeVersion version) |
| | | 618 | | { |
| | 0 | 619 | | string prefix = null; |
| | 0 | 620 | | string ns = null; |
| | 0 | 621 | | if (version == EnvelopeVersion.Soap12) |
| | | 622 | | { |
| | 0 | 623 | | ns = WsdlNS.Soap12Binding.Namespace; |
| | 0 | 624 | | prefix = "soap12"; |
| | | 625 | | } |
| | 0 | 626 | | else if (version == EnvelopeVersion.Soap11) |
| | | 627 | | { |
| | 0 | 628 | | ns = WsdlNS.SoapBinding.Namespace; |
| | 0 | 629 | | prefix = "soap"; |
| | | 630 | | } |
| | | 631 | | |
| | | 632 | | Fx.Assert(ns != null, "EnvelopeVersion is not recognized. Please update the SoapHelper class"); |
| | 0 | 633 | | return Document.CreateElement(prefix, "fault", ns); |
| | | 634 | | } |
| | | 635 | | |
| | | 636 | | public static WsdlNS.SoapAddressBinding GetSoapAddressBinding(WsdlNS.Port wsdlPort) |
| | | 637 | | { |
| | 64 | 638 | | foreach (object o in wsdlPort.Extensions) |
| | | 639 | | { |
| | 0 | 640 | | if (o is WsdlNS.SoapAddressBinding binding) |
| | | 641 | | { |
| | 0 | 642 | | return binding; |
| | | 643 | | } |
| | | 644 | | } |
| | | 645 | | |
| | 32 | 646 | | return null; |
| | 0 | 647 | | } |
| | | 648 | | |
| | | 649 | | internal static WsdlNS.SoapBinding GetSoapBinding(WsdlEndpointConversionContext endpointContext) |
| | | 650 | | { |
| | 124 | 651 | | foreach (object o in endpointContext.WsdlBinding.Extensions) |
| | | 652 | | { |
| | 46 | 653 | | if (o is WsdlNS.SoapBinding binding) |
| | | 654 | | { |
| | 32 | 655 | | return binding; |
| | | 656 | | } |
| | | 657 | | } |
| | | 658 | | |
| | 0 | 659 | | return null; |
| | 32 | 660 | | } |
| | | 661 | | |
| | | 662 | | private static WsdlNS.SoapOperationBinding GetSoapOperationBinding(WsdlEndpointConversionContext endpointContext |
| | | 663 | | { |
| | 159 | 664 | | WsdlNS.OperationBinding wsdlOperationBinding = endpointContext.GetOperationBinding(operation); |
| | | 665 | | |
| | 477 | 666 | | foreach (object o in wsdlOperationBinding.Extensions) |
| | | 667 | | { |
| | 159 | 668 | | if (o is WsdlNS.SoapOperationBinding binding) |
| | | 669 | | { |
| | 159 | 670 | | return binding; |
| | | 671 | | } |
| | | 672 | | } |
| | | 673 | | |
| | 0 | 674 | | return null; |
| | 159 | 675 | | } |
| | | 676 | | |
| | | 677 | | private static WsdlNS.SoapBodyBinding GetSoapBodyBinding(WsdlEndpointConversionContext endpointContext, WsdlNS.M |
| | | 678 | | { |
| | 636 | 679 | | foreach (object o in wsdlMessageBinding.Extensions) |
| | | 680 | | { |
| | 0 | 681 | | if (o is WsdlNS.SoapBodyBinding binding) |
| | | 682 | | { |
| | 0 | 683 | | return binding; |
| | | 684 | | } |
| | | 685 | | } |
| | | 686 | | |
| | 318 | 687 | | return null; |
| | 0 | 688 | | } |
| | | 689 | | |
| | | 690 | | internal static bool IsSoapFaultBinding(XmlElement element) |
| | | 691 | | { |
| | 0 | 692 | | return element != null && element.LocalName == "fault" && (element.NamespaceURI == WsdlNS.Soap12Binding.Name |
| | | 693 | | } |
| | | 694 | | } |
| | | 695 | | } |