| | | 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 CoreWCF.Runtime; |
| | | 6 | | using WsdlNS = System.Web.Services.Description; |
| | | 7 | | |
| | | 8 | | namespace CoreWCF.Description |
| | | 9 | | { |
| | | 10 | | internal static class SoapHelper |
| | | 11 | | { |
| | 0 | 12 | | private static readonly object s_soapVersionStateKey = typeof(Dictionary<WsdlNS.Binding, EnvelopeVersion>); |
| | | 13 | | |
| | | 14 | | internal static WsdlNS.SoapBinding GetOrCreateSoapBinding(WsdlEndpointConversionContext endpointContext, WsdlExp |
| | | 15 | | { |
| | 0 | 16 | | if (GetSoapVersionState(endpointContext.WsdlBinding, exporter) == EnvelopeVersion.None) |
| | | 17 | | { |
| | 0 | 18 | | return null; |
| | | 19 | | } |
| | | 20 | | |
| | 0 | 21 | | WsdlNS.SoapBinding existingSoapBinding = GetSoapBinding(endpointContext); |
| | 0 | 22 | | if (existingSoapBinding != null) |
| | | 23 | | { |
| | 0 | 24 | | return existingSoapBinding; |
| | | 25 | | } |
| | | 26 | | |
| | 0 | 27 | | EnvelopeVersion version = GetSoapVersion(endpointContext.WsdlBinding); |
| | 0 | 28 | | WsdlNS.SoapBinding soapBinding = CreateSoapBinding(version, endpointContext.WsdlBinding); |
| | 0 | 29 | | return soapBinding; |
| | | 30 | | } |
| | | 31 | | |
| | | 32 | | private static WsdlNS.SoapBinding GetSoapBinding(WsdlEndpointConversionContext endpointContext) |
| | | 33 | | { |
| | 0 | 34 | | foreach (object o in endpointContext.WsdlBinding.Extensions) |
| | | 35 | | { |
| | 0 | 36 | | if (o is WsdlNS.SoapBinding binding) |
| | | 37 | | { |
| | 0 | 38 | | return binding; |
| | | 39 | | } |
| | | 40 | | } |
| | | 41 | | |
| | 0 | 42 | | return null; |
| | 0 | 43 | | } |
| | | 44 | | |
| | | 45 | | private static WsdlNS.SoapBinding CreateSoapBinding(EnvelopeVersion version, WsdlNS.Binding wsdlBinding) |
| | | 46 | | { |
| | 0 | 47 | | WsdlNS.SoapBinding soapBinding = null; |
| | | 48 | | |
| | 0 | 49 | | if (version == EnvelopeVersion.Soap12) |
| | | 50 | | { |
| | 0 | 51 | | soapBinding = new WsdlNS.Soap12Binding(); |
| | | 52 | | } |
| | 0 | 53 | | else if (version == EnvelopeVersion.Soap11) |
| | | 54 | | { |
| | 0 | 55 | | soapBinding = new WsdlNS.SoapBinding(); |
| | | 56 | | } |
| | | 57 | | |
| | | 58 | | Fx.Assert(soapBinding != null, "EnvelopeVersion is not recognized. Please update the SoapHelper class"); |
| | | 59 | | |
| | 0 | 60 | | wsdlBinding.Extensions.Add(soapBinding); |
| | 0 | 61 | | return soapBinding; |
| | | 62 | | } |
| | | 63 | | |
| | | 64 | | private static EnvelopeVersion GetSoapVersionState(WsdlNS.Binding wsdlBinding, WsdlExporter exporter) |
| | | 65 | | { |
| | 0 | 66 | | object versions = null; |
| | | 67 | | |
| | 0 | 68 | | if (exporter.State.TryGetValue(s_soapVersionStateKey, out versions)) |
| | | 69 | | { |
| | 0 | 70 | | if (versions != null && ((Dictionary<WsdlNS.Binding, EnvelopeVersion>)versions).ContainsKey(wsdlBinding) |
| | | 71 | | { |
| | 0 | 72 | | return ((Dictionary<WsdlNS.Binding, EnvelopeVersion>)versions)[wsdlBinding]; |
| | | 73 | | } |
| | | 74 | | } |
| | 0 | 75 | | return null; |
| | | 76 | | } |
| | | 77 | | |
| | | 78 | | private static WsdlNS.SoapAddressBinding GetSoapAddressBinding(WsdlNS.Port wsdlPort) |
| | | 79 | | { |
| | 0 | 80 | | foreach (object o in wsdlPort.Extensions) |
| | | 81 | | { |
| | 0 | 82 | | if (o is WsdlNS.SoapAddressBinding binding) |
| | | 83 | | { |
| | 0 | 84 | | return binding; |
| | | 85 | | } |
| | | 86 | | } |
| | 0 | 87 | | return null; |
| | 0 | 88 | | } |
| | | 89 | | |
| | | 90 | | internal static EnvelopeVersion GetSoapVersion(WsdlNS.Binding wsdlBinding) |
| | | 91 | | { |
| | 0 | 92 | | foreach (object o in wsdlBinding.Extensions) |
| | | 93 | | { |
| | 0 | 94 | | if (o is WsdlNS.SoapBinding) |
| | | 95 | | { |
| | 0 | 96 | | return o is WsdlNS.Soap12Binding ? EnvelopeVersion.Soap12 : EnvelopeVersion.Soap11; |
| | | 97 | | } |
| | | 98 | | } |
| | | 99 | | |
| | 0 | 100 | | return EnvelopeVersion.Soap12; |
| | 0 | 101 | | } |
| | | 102 | | |
| | | 103 | | } |
| | | 104 | | } |