| | | 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 CoreWCF.Channels; |
| | | 5 | | using CoreWCF.Runtime; |
| | | 6 | | |
| | | 7 | | namespace CoreWCF |
| | | 8 | | { |
| | | 9 | | public class BasicHttpBinding : HttpBindingBase |
| | | 10 | | { |
| | | 11 | | private BasicHttpSecurity _basicHttpSecurity; |
| | | 12 | | |
| | 558 | 13 | | public BasicHttpBinding() : this(BasicHttpSecurityMode.None) { } |
| | | 14 | | |
| | | 15 | | public BasicHttpBinding(BasicHttpSecurityMode securityMode) |
| | 317 | 16 | | : base() |
| | | 17 | | { |
| | 317 | 18 | | Initialize(); |
| | 317 | 19 | | _basicHttpSecurity.Mode = securityMode; |
| | 317 | 20 | | } |
| | | 21 | | |
| | 3555 | 22 | | public WSMessageEncoding MessageEncoding { get; set; } = BasicHttpBindingDefaults.MessageEncoding; |
| | | 23 | | |
| | 8152 | 24 | | internal override BasicHttpSecurity BasicHttpSecurity => _basicHttpSecurity; |
| | | 25 | | |
| | | 26 | | public BasicHttpSecurity Security |
| | | 27 | | { |
| | 36 | 28 | | get => _basicHttpSecurity; |
| | | 29 | | |
| | | 30 | | set |
| | | 31 | | { |
| | 85 | 32 | | _basicHttpSecurity = value ?? throw Fx.Exception.ArgumentNull(nameof(value)); |
| | 85 | 33 | | } |
| | | 34 | | } |
| | | 35 | | |
| | | 36 | | public override BindingElementCollection CreateBindingElements() |
| | | 37 | | { |
| | 3511 | 38 | | CheckSettings(); |
| | | 39 | | |
| | | 40 | | // return collection of BindingElements |
| | 3511 | 41 | | BindingElementCollection bindingElements = new BindingElementCollection(); |
| | | 42 | | |
| | 3511 | 43 | | SecurityBindingElement wsSecurity = this.BasicHttpSecurity.CreateMessageSecurity(); |
| | 3511 | 44 | | if (wsSecurity != null) |
| | | 45 | | { |
| | 70 | 46 | | bindingElements.Add(wsSecurity); |
| | | 47 | | } |
| | | 48 | | // order of BindingElements is important |
| | | 49 | | // add encoding (text or mtom) |
| | 3511 | 50 | | WSMessageEncodingHelper.SyncUpEncodingBindingElementProperties(TextMessageEncodingBindingElement, MtomMessag |
| | 3511 | 51 | | if (MessageEncoding == WSMessageEncoding.Text) |
| | | 52 | | { |
| | 3472 | 53 | | bindingElements.Add(TextMessageEncodingBindingElement); |
| | | 54 | | } |
| | 39 | 55 | | else if (MessageEncoding == WSMessageEncoding.Mtom) |
| | | 56 | | { |
| | 39 | 57 | | bindingElements.Add(MtomMessageEncodingBindingElement); |
| | | 58 | | } |
| | | 59 | | // add transport (http or https) |
| | 3511 | 60 | | bindingElements.Add(GetTransport()); |
| | | 61 | | |
| | 3511 | 62 | | return bindingElements.Clone(); |
| | | 63 | | } |
| | | 64 | | |
| | | 65 | | private void Initialize() |
| | | 66 | | { |
| | 317 | 67 | | _basicHttpSecurity = new BasicHttpSecurity(); |
| | 317 | 68 | | } |
| | | 69 | | } |
| | | 70 | | } |