| | | 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; |
| | | 5 | | using System.Xml; |
| | | 6 | | using CoreWCF.Channels; |
| | | 7 | | using CoreWCF.Runtime; |
| | | 8 | | |
| | | 9 | | namespace CoreWCF |
| | | 10 | | { |
| | | 11 | | public class NetHttpBinding : HttpBindingBase |
| | | 12 | | { |
| | | 13 | | private BinaryMessageEncodingBindingElement _binaryMessageEncodingBindingElement; |
| | | 14 | | private BasicHttpSecurity _basicHttpSecurity; |
| | | 15 | | |
| | | 16 | | public NetHttpBinding() |
| | 10 | 17 | | : this(BasicHttpSecurityMode.None) |
| | | 18 | | { |
| | 10 | 19 | | } |
| | | 20 | | |
| | | 21 | | public NetHttpBinding(BasicHttpSecurityMode securityMode) |
| | 25 | 22 | | : base() |
| | | 23 | | { |
| | 25 | 24 | | Initialize(); |
| | 25 | 25 | | _basicHttpSecurity.Mode = securityMode; |
| | 25 | 26 | | } |
| | | 27 | | |
| | 326 | 28 | | public NetHttpMessageEncoding MessageEncoding { get; set; } |
| | | 29 | | |
| | | 30 | | public BasicHttpSecurity Security |
| | | 31 | | { |
| | 4 | 32 | | get => _basicHttpSecurity; |
| | | 33 | | |
| | | 34 | | set |
| | | 35 | | { |
| | 0 | 36 | | _basicHttpSecurity = value ?? throw Fx.Exception.ArgumentNull(nameof(value)); |
| | 0 | 37 | | } |
| | | 38 | | } |
| | | 39 | | |
| | 62 | 40 | | public WebSocketTransportSettings WebSocketSettings => InternalWebSocketSettings; |
| | | 41 | | |
| | 338 | 42 | | internal override BasicHttpSecurity BasicHttpSecurity => _basicHttpSecurity; |
| | | 43 | | |
| | | 44 | | internal override void SetReaderQuotas(XmlDictionaryReaderQuotas readerQuotas) |
| | | 45 | | { |
| | 2 | 46 | | readerQuotas.CopyTo(_binaryMessageEncodingBindingElement.ReaderQuotas); |
| | 2 | 47 | | } |
| | | 48 | | |
| | | 49 | | public override BindingElementCollection CreateBindingElements() |
| | | 50 | | { |
| | 279 | 51 | | CheckSettings(); |
| | | 52 | | |
| | | 53 | | // return collection of BindingElements |
| | 279 | 54 | | BindingElementCollection bindingElements = new BindingElementCollection(); |
| | | 55 | | |
| | | 56 | | // order of BindingElements is important |
| | | 57 | | // add encoding |
| | 279 | 58 | | switch (MessageEncoding) |
| | | 59 | | { |
| | | 60 | | case NetHttpMessageEncoding.Text: |
| | 80 | 61 | | bindingElements.Add(TextMessageEncodingBindingElement); |
| | 80 | 62 | | break; |
| | | 63 | | case NetHttpMessageEncoding.Mtom: |
| | 78 | 64 | | bindingElements.Add(MtomMessageEncodingBindingElement); |
| | 78 | 65 | | break; |
| | | 66 | | default: |
| | 121 | 67 | | bindingElements.Add(_binaryMessageEncodingBindingElement); |
| | | 68 | | break; |
| | | 69 | | } |
| | | 70 | | |
| | | 71 | | // add transport (http or https) |
| | 279 | 72 | | bindingElements.Add(GetTransport()); |
| | | 73 | | |
| | 279 | 74 | | return bindingElements.Clone(); |
| | | 75 | | } |
| | | 76 | | |
| | | 77 | | internal override void CheckSettings() |
| | | 78 | | { |
| | 279 | 79 | | base.CheckSettings(); |
| | 279 | 80 | | } |
| | | 81 | | |
| | | 82 | | private void Initialize() |
| | | 83 | | { |
| | 25 | 84 | | MessageEncoding = NetHttpBindingDefaults.MessageEncoding; |
| | 25 | 85 | | _binaryMessageEncodingBindingElement = new BinaryMessageEncodingBindingElement() { MessageVersion = MessageV |
| | 25 | 86 | | TextMessageEncodingBindingElement.MessageVersion = MessageVersion.Soap12WSAddressing10; |
| | 25 | 87 | | MtomMessageEncodingBindingElement.MessageVersion = MessageVersion.Soap12WSAddressing10; |
| | 25 | 88 | | WebSocketSettings.TransportUsage = NetHttpBindingDefaults.TransportUsage; |
| | 25 | 89 | | WebSocketSettings.SubProtocol = WebSocketTransportSettings.SoapSubProtocol; |
| | 25 | 90 | | _basicHttpSecurity = new BasicHttpSecurity(); |
| | 25 | 91 | | } |
| | | 92 | | } |
| | | 93 | | } |