| | | 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.Runtime.Versioning; |
| | | 6 | | using System.Xml; |
| | | 7 | | using CoreWCF.Channels; |
| | | 8 | | |
| | | 9 | | namespace CoreWCF |
| | | 10 | | { |
| | | 11 | | [SupportedOSPlatform("windows")] |
| | | 12 | | public class NetNamedPipeBinding : Binding |
| | | 13 | | { |
| | | 14 | | // private BindingElements |
| | | 15 | | //TransactionFlowBindingElement context; |
| | | 16 | | private BinaryMessageEncodingBindingElement _encoding; |
| | | 17 | | private NamedPipeTransportBindingElement _namedPipe; |
| | 0 | 18 | | private NetNamedPipeSecurity _security = new NetNamedPipeSecurity(); |
| | | 19 | | |
| | | 20 | | public NetNamedPipeBinding() |
| | 0 | 21 | | : base() |
| | | 22 | | { |
| | 0 | 23 | | Initialize(); |
| | 0 | 24 | | } |
| | | 25 | | |
| | | 26 | | public NetNamedPipeBinding(NetNamedPipeSecurityMode securityMode) |
| | 0 | 27 | | : this() |
| | | 28 | | { |
| | 0 | 29 | | _security.Mode = securityMode; |
| | 0 | 30 | | } |
| | | 31 | | |
| | | 32 | | private NetNamedPipeBinding(NetNamedPipeSecurity security) |
| | 0 | 33 | | : this() |
| | | 34 | | { |
| | 0 | 35 | | _security = security; |
| | 0 | 36 | | } |
| | | 37 | | |
| | | 38 | | // The following properties have moved to NamedPipeListenOptions as that's the |
| | | 39 | | // equivalent of the shared listeners from WCF |
| | | 40 | | // ConnectionBufferSize |
| | | 41 | | // HostNameComparisonMode |
| | | 42 | | // MaxPendingAccepts |
| | | 43 | | |
| | | 44 | | //[DefaultValue(TransactionFlowDefaults.Transactions)] |
| | | 45 | | //public bool TransactionFlow |
| | | 46 | | //{ |
| | | 47 | | // get { return context.Transactions; } |
| | | 48 | | // set { context.Transactions = value; } |
| | | 49 | | //} |
| | | 50 | | |
| | | 51 | | //public TransactionProtocol TransactionProtocol |
| | | 52 | | //{ |
| | | 53 | | // get { return this.context.TransactionProtocol; } |
| | | 54 | | // set { this.context.TransactionProtocol = value; } |
| | | 55 | | //} |
| | | 56 | | |
| | | 57 | | [DefaultValue(ConnectionOrientedTransportDefaults.TransferMode)] |
| | | 58 | | public TransferMode TransferMode |
| | | 59 | | { |
| | 0 | 60 | | get { return _namedPipe.TransferMode; } |
| | 0 | 61 | | set { _namedPipe.TransferMode = value; } |
| | | 62 | | } |
| | | 63 | | |
| | | 64 | | [DefaultValue(TransportDefaults.MaxBufferPoolSize)] |
| | | 65 | | public long MaxBufferPoolSize |
| | | 66 | | { |
| | 0 | 67 | | get { return _namedPipe.MaxBufferPoolSize; } |
| | | 68 | | set |
| | | 69 | | { |
| | 0 | 70 | | _namedPipe.MaxBufferPoolSize = value; |
| | 0 | 71 | | } |
| | | 72 | | } |
| | | 73 | | |
| | | 74 | | [DefaultValue(TransportDefaults.MaxBufferSize)] |
| | | 75 | | public int MaxBufferSize |
| | | 76 | | { |
| | 0 | 77 | | get { return _namedPipe.MaxBufferSize; } |
| | 0 | 78 | | set { _namedPipe.MaxBufferSize = value; } |
| | | 79 | | } |
| | | 80 | | |
| | | 81 | | public int MaxConnections |
| | | 82 | | { |
| | 0 | 83 | | get { return _namedPipe.MaxPendingConnections; } |
| | | 84 | | set |
| | | 85 | | { |
| | 0 | 86 | | _namedPipe.MaxPendingConnections = value; |
| | 0 | 87 | | } |
| | | 88 | | } |
| | | 89 | | |
| | | 90 | | [DefaultValue(TransportDefaults.MaxReceivedMessageSize)] |
| | | 91 | | public long MaxReceivedMessageSize |
| | | 92 | | { |
| | 0 | 93 | | get { return _namedPipe.MaxReceivedMessageSize; } |
| | 0 | 94 | | set { _namedPipe.MaxReceivedMessageSize = value; } |
| | | 95 | | } |
| | | 96 | | |
| | | 97 | | public XmlDictionaryReaderQuotas ReaderQuotas |
| | | 98 | | { |
| | 0 | 99 | | get { return _encoding.ReaderQuotas; } |
| | | 100 | | set |
| | | 101 | | { |
| | 0 | 102 | | if (value == null) |
| | 0 | 103 | | throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(value)); |
| | 0 | 104 | | value.CopyTo(_encoding.ReaderQuotas); |
| | 0 | 105 | | } |
| | | 106 | | } |
| | | 107 | | |
| | 0 | 108 | | public override string Scheme { get { return _namedPipe.Scheme; } } |
| | | 109 | | |
| | | 110 | | public EnvelopeVersion EnvelopeVersion |
| | | 111 | | { |
| | 0 | 112 | | get { return EnvelopeVersion.Soap12; } |
| | | 113 | | } |
| | | 114 | | |
| | | 115 | | public NetNamedPipeSecurity Security |
| | | 116 | | { |
| | 0 | 117 | | get { return _security; } |
| | | 118 | | set |
| | | 119 | | { |
| | 0 | 120 | | if (value == null) |
| | 0 | 121 | | throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("value"); |
| | 0 | 122 | | _security = value; |
| | 0 | 123 | | } |
| | | 124 | | } |
| | | 125 | | |
| | | 126 | | private void Initialize() |
| | | 127 | | { |
| | 0 | 128 | | _namedPipe = new NamedPipeTransportBindingElement(); |
| | 0 | 129 | | _encoding = new BinaryMessageEncodingBindingElement(); |
| | | 130 | | //context = GetDefaultTransactionFlowBindingElement(); |
| | 0 | 131 | | } |
| | | 132 | | |
| | | 133 | | public override BindingElementCollection CreateBindingElements() |
| | | 134 | | { // return collection of BindingElements |
| | 0 | 135 | | BindingElementCollection bindingElements = new BindingElementCollection(); |
| | | 136 | | // order of BindingElements is important |
| | | 137 | | // add context |
| | | 138 | | //bindingElements.Add(context); |
| | | 139 | | // add encoding |
| | 0 | 140 | | bindingElements.Add(_encoding); |
| | | 141 | | // add transport security |
| | 0 | 142 | | WindowsStreamSecurityBindingElement transportSecurity = CreateTransportSecurity(); |
| | 0 | 143 | | if (transportSecurity != null) |
| | | 144 | | { |
| | 0 | 145 | | bindingElements.Add(transportSecurity); |
| | | 146 | | } |
| | | 147 | | // add transport (named pipes) |
| | 0 | 148 | | bindingElements.Add(_namedPipe); |
| | | 149 | | |
| | 0 | 150 | | return bindingElements.Clone(); |
| | | 151 | | } |
| | | 152 | | |
| | | 153 | | private WindowsStreamSecurityBindingElement CreateTransportSecurity() |
| | | 154 | | { |
| | 0 | 155 | | if (_security.Mode == NetNamedPipeSecurityMode.Transport) |
| | | 156 | | { |
| | 0 | 157 | | return _security.CreateTransportSecurity(); |
| | | 158 | | } |
| | | 159 | | else |
| | | 160 | | { |
| | 0 | 161 | | return null; |
| | | 162 | | } |
| | | 163 | | } |
| | | 164 | | } |
| | | 165 | | } |