| | | 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.ComponentModel; |
| | | 5 | | using System.Xml; |
| | | 6 | | using CoreWCF.Runtime; |
| | | 7 | | |
| | | 8 | | namespace CoreWCF.Channels |
| | | 9 | | { |
| | | 10 | | public class NetMsmqBinding : MsmqBindingBase |
| | | 11 | | { |
| | | 12 | | // private BindingElements |
| | | 13 | | private BinaryMessageEncodingBindingElement _encoding; |
| | | 14 | | private NetMsmqSecurity _security; |
| | | 15 | | |
| | 0 | 16 | | public NetMsmqBinding() |
| | | 17 | | { |
| | 0 | 18 | | Initialize(); |
| | 0 | 19 | | _security = new NetMsmqSecurity(); |
| | 0 | 20 | | } |
| | | 21 | | |
| | 0 | 22 | | public NetMsmqBinding(string configurationName) |
| | | 23 | | { |
| | 0 | 24 | | Initialize(); |
| | 0 | 25 | | _security = new NetMsmqSecurity(); |
| | 0 | 26 | | } |
| | | 27 | | |
| | 0 | 28 | | public NetMsmqBinding(NetMsmqSecurityMode securityMode) |
| | | 29 | | { |
| | 0 | 30 | | Initialize(); |
| | 0 | 31 | | _security = new NetMsmqSecurity(securityMode); |
| | 0 | 32 | | } |
| | | 33 | | |
| | 0 | 34 | | private NetMsmqBinding(NetMsmqSecurity security) |
| | | 35 | | { |
| | 0 | 36 | | Initialize(); |
| | | 37 | | Fx.Assert(security != null, "Invalid (null) NetMsmqSecurity value"); |
| | 0 | 38 | | _security = security; |
| | 0 | 39 | | } |
| | | 40 | | |
| | | 41 | | public XmlDictionaryReaderQuotas ReaderQuotas |
| | | 42 | | { |
| | 0 | 43 | | get { return _encoding.ReaderQuotas; } |
| | | 44 | | set |
| | | 45 | | { |
| | 0 | 46 | | if (value == null) |
| | 0 | 47 | | throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(value)); |
| | 0 | 48 | | value.CopyTo(_encoding.ReaderQuotas); |
| | 0 | 49 | | } |
| | | 50 | | } |
| | | 51 | | |
| | | 52 | | public NetMsmqSecurity Security |
| | | 53 | | { |
| | 0 | 54 | | get { return _security; } |
| | 0 | 55 | | set { _security = value; } |
| | | 56 | | } |
| | | 57 | | |
| | | 58 | | public EnvelopeVersion EnvelopeVersion |
| | | 59 | | { |
| | 0 | 60 | | get { return EnvelopeVersion.Soap12; } |
| | | 61 | | } |
| | | 62 | | |
| | | 63 | | // [DefaultValue(TransportDefaults.MaxBufferPoolSize)] |
| | | 64 | | public long MaxBufferPoolSize |
| | | 65 | | { |
| | 0 | 66 | | get { return _transport.MaxBufferPoolSize; } |
| | 0 | 67 | | set { _transport.MaxBufferPoolSize = value; } |
| | | 68 | | } |
| | | 69 | | |
| | | 70 | | [DefaultValue(MsmqDefaults.UseActiveDirectory)] |
| | | 71 | | public bool UseActiveDirectory |
| | | 72 | | { |
| | 0 | 73 | | get { return (_transport as MsmqTransportBindingElement).UseActiveDirectory; } |
| | 0 | 74 | | set { (_transport as MsmqTransportBindingElement).UseActiveDirectory = value; } |
| | | 75 | | } |
| | | 76 | | |
| | | 77 | | [EditorBrowsable(EditorBrowsableState.Never)] |
| | | 78 | | public bool ShouldSerializeSecurity() |
| | | 79 | | { |
| | 0 | 80 | | if (_security.Mode != NetMsmqSecurity.DefaultMode) |
| | | 81 | | { |
| | 0 | 82 | | return true; |
| | | 83 | | } |
| | | 84 | | |
| | 0 | 85 | | if (_security.Transport.MsmqAuthenticationMode != MsmqDefaults.MsmqAuthenticationMode1 || |
| | 0 | 86 | | _security.Transport.MsmqEncryptionAlgorithm != MsmqDefaults.MsmqEncryptionAlgorithm1 || |
| | 0 | 87 | | _security.Transport.MsmqSecureHashAlgorithm != MsmqDefaults.MsmqSecureHashAlgorithm || |
| | 0 | 88 | | _security.Transport.MsmqProtectionLevel != MsmqDefaults.MsmqProtectionLevel) |
| | | 89 | | { |
| | 0 | 90 | | return true; |
| | | 91 | | } |
| | | 92 | | |
| | | 93 | | //if (this.security.Message.AlgorithmSuite != MsmqDefaults.MessageSecurityAlgorithmSuite || |
| | | 94 | | //this.security.Message.ClientCredentialType != MsmqDefaults.DefaultClientCredentialType) |
| | | 95 | | //{ |
| | | 96 | | // return true; |
| | | 97 | | //} |
| | 0 | 98 | | return false; |
| | | 99 | | } |
| | | 100 | | |
| | | 101 | | private void Initialize() |
| | | 102 | | { |
| | 0 | 103 | | _transport = new MsmqTransportBindingElement(); |
| | 0 | 104 | | _encoding = new BinaryMessageEncodingBindingElement(); |
| | 0 | 105 | | } |
| | | 106 | | |
| | | 107 | | public override BindingElementCollection CreateBindingElements() |
| | | 108 | | { |
| | | 109 | | // return collection of BindingElements |
| | 0 | 110 | | BindingElementCollection bindingElements = new BindingElementCollection(); |
| | | 111 | | // order of BindingElements is important |
| | | 112 | | // add security |
| | 0 | 113 | | SecurityBindingElement wsSecurity = CreateMessageSecurity(); |
| | 0 | 114 | | if (wsSecurity != null) |
| | | 115 | | { |
| | 0 | 116 | | bindingElements.Add(wsSecurity); |
| | | 117 | | } |
| | | 118 | | |
| | | 119 | | // add encoding (text or mtom) |
| | 0 | 120 | | bindingElements.Add(_encoding); |
| | | 121 | | // add transport |
| | 0 | 122 | | bindingElements.Add(GetTransport()); |
| | | 123 | | |
| | 0 | 124 | | return bindingElements.Clone(); |
| | | 125 | | } |
| | | 126 | | |
| | | 127 | | private SecurityBindingElement CreateMessageSecurity() |
| | | 128 | | { |
| | 0 | 129 | | if (_security.Mode == NetMsmqSecurityMode.Message || _security.Mode == NetMsmqSecurityMode.Both) |
| | | 130 | | { |
| | 0 | 131 | | return _security.CreateMessageSecurity(); |
| | | 132 | | } |
| | | 133 | | |
| | 0 | 134 | | return null; |
| | | 135 | | } |
| | | 136 | | |
| | | 137 | | private MsmqBindingElementBase GetTransport() |
| | | 138 | | { |
| | 0 | 139 | | _security.ConfigureTransportSecurity(_transport); |
| | 0 | 140 | | return _transport; |
| | | 141 | | } |
| | | 142 | | } |
| | | 143 | | } |