public static void LeaseTimeout_Property_Set_Invalid_Value_Throws(TimeSpan timeSpan) { // TcpConnectionPoolSettings has no public constructor but we can access it from the TcpTransportBindingElement TcpTransportBindingElement element = new TcpTransportBindingElement(); TcpConnectionPoolSettings settings = element.ConnectionPoolSettings; Assert.Throws<ArgumentOutOfRangeException>(() => settings.LeaseTimeout = timeSpan); }
private static CustomBinding CreateTcpBinding() { CustomBinding binding = new CustomBinding("MetadataExchangeTcpBinding", "http://schemas.microsoft.com/ws/2005/02/mex/bindings", new BindingElement[0]); TcpTransportBindingElement item = new TcpTransportBindingElement(); binding.Elements.Add(item); return binding; }
internal NetTcpBinding(TcpTransportBindingElement transport, NetTcpSecurity security, bool reliableSessionEnabled) { this.transport = transport; this.security = security; }
private void CreateBinding() { Collection<BindingElement> bindingElementsInTopDownChannelStackOrder = new Collection<BindingElement>(); BindingElement securityBindingElement = this.config.SecurityManager.GetSecurityBindingElement(); if (securityBindingElement != null) { bindingElementsInTopDownChannelStackOrder.Add(securityBindingElement); } TcpTransportBindingElement item = new TcpTransportBindingElement { MaxReceivedMessageSize = this.config.MaxReceivedMessageSize, MaxBufferPoolSize = this.config.MaxBufferPoolSize, TeredoEnabled = true }; MessageEncodingBindingElement encodingBindingElement = null; if (this.messageHandler != null) { encodingBindingElement = this.messageHandler.EncodingBindingElement; } if (encodingBindingElement == null) { BinaryMessageEncodingBindingElement element4 = new BinaryMessageEncodingBindingElement(); this.config.ReaderQuotas.CopyTo(element4.ReaderQuotas); bindingElementsInTopDownChannelStackOrder.Add(element4); } else { bindingElementsInTopDownChannelStackOrder.Add(encodingBindingElement); } bindingElementsInTopDownChannelStackOrder.Add(item); this.binding = new CustomBinding(bindingElementsInTopDownChannelStackOrder); this.binding.ReceiveTimeout = TimeSpan.MaxValue; }
private void InitializeFrom(TcpTransportBindingElement transport, BinaryMessageEncodingBindingElement encoding, TransactionFlowBindingElement context, ReliableSessionBindingElement session) { // TODO: Fx.Assert(transport != null, "Invalid (null) transport value."); // TODO: Fx.Assert(encoding != null, "Invalid (null) encoding value."); // TODO: Fx.Assert(context != null, "Invalid (null) context value."); // TODO: Fx.Assert(security != null, "Invalid (null) security value."); // transport this.HostNameComparisonMode = transport.HostNameComparisonMode; this.MaxBufferPoolSize = transport.MaxBufferPoolSize; this.MaxBufferSize = transport.MaxBufferSize; this.MaxReceivedMessageSize = transport.MaxReceivedMessageSize; this.PortSharingEnabled = transport.PortSharingEnabled; this.TransferMode = transport.TransferMode; // encoding this.ReaderQuotas = encoding.ReaderQuotas; // context this.TransactionFlow = context.Transactions; this.TransactionProtocol = context.TransactionProtocol; //session if (session != null) { // only set properties that have standard binding manifestations _session.InactivityTimeout = session.InactivityTimeout; _session.Ordered = session.Ordered; } }
static void Run() { SymmetricSecurityBindingElement sbe = new SymmetricSecurityBindingElement(); sbe.MessageSecurityVersion = MessageSecurityVersion.WSSecurity11WSTrustFebruary2005WSSecureConversationFebruary2005WSSecurityPolicy11BasicSecurityProfile10; sbe.RequireSignatureConfirmation = true; //sbe.IncludeTimestamp = false; X509SecurityTokenParameters p = new X509SecurityTokenParameters(X509KeyIdentifierClauseType.Thumbprint, SecurityTokenInclusionMode.AlwaysToRecipient); p.RequireDerivedKeys = false; sbe.EndpointSupportingTokenParameters.Endorsing.Add(p); sbe.ProtectionTokenParameters = new X509SecurityTokenParameters(X509KeyIdentifierClauseType.Thumbprint, SecurityTokenInclusionMode.Never); //sbe.SetKeyDerivation (false); //sbe.MessageProtectionOrder = MessageProtectionOrder.SignBeforeEncrypt; var mbe = new BinaryMessageEncodingBindingElement(); var tbe = new TcpTransportBindingElement(); CustomBinding binding = new CustomBinding(new XBE(), sbe, mbe, tbe); X509Certificate2 cert = new X509Certificate2("test.pfx", "mono"); X509Certificate2 cert2 = cert; //new X509Certificate2 ("test2.cer"); FooProxy proxy = new FooProxy(binding, new EndpointAddress(new Uri("http://localhost:8080"), new X509CertificateEndpointIdentity(cert2))); //proxy.ClientCredentials.ServiceCertificate.Authentication.CertificateValidationMode = X509CertificateValidationMode.None; proxy.ClientCredentials.ClientCertificate.Certificate = cert; proxy.Open(); Console.WriteLine(proxy.Echo("TEST FOR ECHO")); }
// check that properties of the HttpTransportBindingElement and // MessageEncodingBindingElement not exposed as properties on BasicHttpBinding // match default values of the binding elements private bool IsBindingElementsMatch(TcpTransportBindingElement transport, BinaryMessageEncodingBindingElement encoding, TransactionFlowBindingElement context, ReliableSessionBindingElement session) { if (!_transport.IsMatch(transport)) { return(false); } if (!_encoding.IsMatch(encoding)) { return(false); } if (!_context.IsMatch(context)) { return(false); } if (_reliableSession.Enabled) { if (!_session.IsMatch(session)) { return(false); } } else if (session != null) { return(false); } return(true); }
// check that properties of the HttpTransportBindingElement and // MessageEncodingBindingElement not exposed as properties on BasicHttpBinding // match default values of the binding elements private bool IsBindingElementsMatch(TcpTransportBindingElement transport, BinaryMessageEncodingBindingElement encoding) { if (!_transport.IsMatch(transport)) { return(false); } if (!_encoding.IsMatch(encoding)) { return(false); } if (!_context.IsMatch(_context)) { return(false); } if (_reliableSession.Enabled) { if (!_session.IsMatch(_session)) { return(false); } } return(true); }
private NetTcpBinding(TcpTransportBindingElement transport, BinaryMessageEncodingBindingElement encoding, NetTcpSecurity security) : this() { _security = security; }
private NetTcpBinding(TcpTransportBindingElement transport, BinaryMessageEncodingBindingElement encoding, TransactionFlowBindingElement context, ReliableSessionBindingElement session, NetTcpSecurity security) : this() { _security = security; this.ReliableSession.Enabled = session != null; InitializeFrom(transport, encoding, context, session); }
NetTcpBinding(TcpTransportBindingElement transport, BinaryMessageEncodingBindingElement encoding, TransactionFlowBindingElement context, ReliableSessionBindingElement session, NetTcpSecurity security) : this() { this.security = security; this.ReliableSession.Enabled = session != null; InitializeFrom(transport, encoding, context, session); }
/// <summary> /// 功能:添加元数据交换终结点 /// </summary> private void AddAllMexEndPoint() { foreach (Uri baseAddress in BaseAddresses) { BindingElement beTemp = null; switch (baseAddress.Scheme.Trim().ToLower()) { case "net.tcp": beTemp = new TcpTransportBindingElement(); break; case "net.pipe": beTemp = new NamedPipeTransportBindingElement(); break; case "http": beTemp = new HttpTransportBindingElement(); break; case "https": beTemp = new HttpsTransportBindingElement(); break; } if (null != beTemp) { Binding bdTemp = new CustomBinding(beTemp); AddServiceEndpoint(typeof(IMetadataExchange), bdTemp, "Mex"); } } }
public void CanBuildChannelFactory() { // with HttpTransport var m = new WebMessageEncodingBindingElement(); Assert.IsTrue(m.CanBuildChannelFactory <IRequestChannel> (CreateBindingContext()), "#1"); Assert.IsFalse(m.CanBuildChannelFactory <IReplyChannel> (CreateBindingContext()), "#2"); Assert.IsFalse(m.CanBuildChannelFactory <IRequestSessionChannel> (CreateBindingContext()), "#3"); Assert.IsFalse(m.CanBuildChannelFactory <IDuplexChannel> (CreateBindingContext()), "#4"); // actually they are from transport var h = new HttpTransportBindingElement(); Assert.IsTrue(h.CanBuildChannelFactory <IRequestChannel> (CreateBindingContext()), "#5"); Assert.IsFalse(h.CanBuildChannelFactory <IReplyChannel> (CreateBindingContext()), "#6"); Assert.IsFalse(h.CanBuildChannelFactory <IRequestSessionChannel> (CreateBindingContext()), "#7"); Assert.IsFalse(h.CanBuildChannelFactory <IDuplexChannel> (CreateBindingContext()), "#8"); // with TcpTransport Assert.IsFalse(m.CanBuildChannelFactory <IRequestChannel> (CreateBindingContext2()), "#9"); Assert.IsFalse(m.CanBuildChannelFactory <IReplyChannel> (CreateBindingContext2()), "#10"); Assert.IsFalse(m.CanBuildChannelFactory <IRequestSessionChannel> (CreateBindingContext2()), "#11"); Assert.IsFalse(m.CanBuildChannelFactory <IDuplexChannel> (CreateBindingContext2()), "#12"); // ... yes, actually they are from transport var t = new TcpTransportBindingElement(); Assert.IsFalse(t.CanBuildChannelFactory <IRequestChannel> (CreateBindingContext2()), "#13"); Assert.IsFalse(t.CanBuildChannelFactory <IReplyChannel> (CreateBindingContext2()), "#14"); Assert.IsFalse(t.CanBuildChannelFactory <IRequestSessionChannel> (CreateBindingContext2()), "#15"); Assert.IsFalse(t.CanBuildChannelFactory <IDuplexChannel> (CreateBindingContext2()), "#16"); }
/// <summary> /// Try reconnect to server. /// </summary> private void TryReConnect() { var baseAddress = new Uri(string.Format("net.tcp://{0}:{1}/AutoCompleteWcfService", this._host, this._port)); var bindingElements = new List <BindingElement>(); var httpBindingElement = new TcpTransportBindingElement(); var textBindingElement = new CustomTextMessageBindingElement("us-ascii"); bindingElements.Add(textBindingElement); bindingElements.Add(httpBindingElement); var binding = new CustomBinding(bindingElements); var adress = new EndpointAddress(baseAddress); this.client = new AutoCompleteWcfServiceClient(binding, adress); try { this.client.Open(); } catch (ChannelTerminatedException) { } catch (EndpointNotFoundException) { } catch (ServerTooBusyException) { } catch (TimeoutException) { } catch (CommunicationException) { } }
public void CanBuildChannelListener2() { TcpTransportBindingElement be = new TcpTransportBindingElement(); be.TransferMode = TransferMode.Streamed; BindingContext ctx = new BindingContext( new CustomBinding(), empty_params); Assert.IsTrue(be.CanBuildChannelListener <IReplyChannel> (ctx), "#1"); Assert.IsFalse(be.CanBuildChannelListener <IOutputChannel> (ctx), "#2"); Assert.IsFalse(be.CanBuildChannelListener <IRequestChannel> (ctx), "#3"); Assert.IsFalse(be.CanBuildChannelListener <IInputChannel> (ctx), "#4"); Assert.IsFalse(be.CanBuildChannelListener <IReplySessionChannel> (ctx), "#5"); Assert.IsFalse(be.CanBuildChannelListener <IOutputSessionChannel> (ctx), "#6"); Assert.IsFalse(be.CanBuildChannelListener <IRequestSessionChannel> (ctx), "#7"); Assert.IsFalse(be.CanBuildChannelListener <IInputSessionChannel> (ctx), "#8"); // IServiceChannel is not supported Assert.IsFalse(be.CanBuildChannelListener <IServiceChannel> (ctx), "#9"); Assert.IsFalse(be.CanBuildChannelListener <IClientChannel> (ctx), "#10"); Assert.IsFalse(be.CanBuildChannelListener <IDuplexChannel> (ctx), "#11"); Assert.IsFalse(be.CanBuildChannelListener <IDuplexSessionChannel> (ctx), "#12"); }
internal NetTcpBinding (TcpTransportBindingElement transport, NetTcpSecurity security, bool reliableSessionEnabled) { this.transport = transport; this.security = security; }
public void DefaultValues() { TcpTransportBindingElement be = new TcpTransportBindingElement(); Assert.AreEqual(TimeSpan.FromSeconds(5), be.ChannelInitializationTimeout, "#1"); Assert.AreEqual(0x2000, be.ConnectionBufferSize, "#2"); Assert.AreEqual(HostNameComparisonMode.StrongWildcard, be.HostNameComparisonMode, "#3"); Assert.AreEqual(0x10000, be.MaxBufferSize, "#4"); Assert.AreEqual(TimeSpan.FromMilliseconds(200), be.MaxOutputDelay, "#5"); Assert.AreEqual(1, be.MaxPendingAccepts, "#6"); Assert.AreEqual(10, be.MaxPendingConnections, "#7"); Assert.AreEqual(TransferMode.Buffered, be.TransferMode, "#8"); Assert.AreEqual(10, be.ListenBacklog, "#9"); Assert.IsFalse(be.PortSharingEnabled, "#10"); Assert.AreEqual("net.tcp", be.Scheme, "#11"); Assert.IsFalse(be.TeredoEnabled, "#12"); TcpConnectionPoolSettings pool = be.ConnectionPoolSettings; Assert.IsNotNull(pool, "#13"); Assert.AreEqual("default", pool.GroupName, "#14"); Assert.AreEqual(TimeSpan.FromSeconds(120), pool.IdleTimeout, "#15"); Assert.AreEqual(TimeSpan.FromSeconds(300), pool.LeaseTimeout, "#16"); Assert.AreEqual(10, pool.MaxOutboundConnectionsPerEndpoint, "#17"); }
private static NetworkDetector.ConnectivityStatus CheckTcpConnectivity(Uri baseAddress, out Exception exception) { NetworkDetector.ConnectivityStatus connectivityStatu = NetworkDetector.ConnectivityStatus.Unavailable; exception = null; if (!RelayEnvironment.GetEnvironmentVariable("RELAYFORCEHTTP", false) && !RelayEnvironment.GetEnvironmentVariable("RELAYFORCEHTTPS", false)) { try { BinaryMessageEncodingBindingElement binaryMessageEncodingBindingElement = new BinaryMessageEncodingBindingElement(); TcpTransportBindingElement tcpTransportBindingElement = new TcpTransportBindingElement(); tcpTransportBindingElement.ConnectionPoolSettings.MaxOutboundConnectionsPerEndpoint = 100; tcpTransportBindingElement.MaxReceivedMessageSize = (long)65536; CustomBinding customBinding = new CustomBinding(); customBinding.Elements.Add(binaryMessageEncodingBindingElement); customBinding.Elements.Add(tcpTransportBindingElement); customBinding.OpenTimeout = TimeSpan.FromSeconds(10); customBinding.SendTimeout = TimeSpan.FromSeconds(10); customBinding.ReceiveTimeout = TimeSpan.MaxValue; int num = 9350; Uri uri = ServiceBusUriHelper.CreateServiceUri("net.tcp", string.Concat(baseAddress.DnsSafeHost, ":", num.ToString(CultureInfo.InvariantCulture)), "/"); IChannelFactory <IDuplexSessionChannel> channelFactory = null; IDuplexSessionChannel duplexSessionChannel = null; try { channelFactory = customBinding.BuildChannelFactory <IDuplexSessionChannel>(new object[0]); channelFactory.Open(); duplexSessionChannel = channelFactory.CreateChannel(new EndpointAddress(uri, new AddressHeader[0])); duplexSessionChannel.Open(); Message message = Message.CreateMessage(MessageVersion.Default, "http://schemas.microsoft.com/netservices/2009/05/servicebus/connect/OnewayPing", new OnewayPingMessage()); duplexSessionChannel.Send(message, customBinding.SendTimeout); duplexSessionChannel.Close(); duplexSessionChannel = null; channelFactory.Close(); channelFactory = null; } finally { if (duplexSessionChannel != null) { duplexSessionChannel.Abort(); } if (channelFactory != null) { channelFactory.Abort(); } } connectivityStatu = NetworkDetector.ConnectivityStatus.Available; } catch (CommunicationException communicationException) { exception = communicationException; } catch (TimeoutException timeoutException) { exception = timeoutException; } } NetworkDetector.LogResult(baseAddress, "Tcp", connectivityStatu); return(connectivityStatu); }
public static void GroupName_Property_Set_Null_Value_Throws() { // TcpConnectionPoolSettings has no public constructor but we can access it from the TcpTransportBindingElement TcpTransportBindingElement element = new TcpTransportBindingElement(); TcpConnectionPoolSettings settings = element.ConnectionPoolSettings; Assert.Throws<ArgumentNullException>(() => settings.GroupName = null); }
private static Binding GetBinding(int maxPending) { if (maxPending < Environment.ProcessorCount || maxPending > 1000) { throw new ArgumentOutOfRangeException("maxPending", maxPending, "Invalid value"); } var transport = new TcpTransportBindingElement { HostNameComparisonMode = HostNameComparisonMode.WeakWildcard, TransferMode = TransferMode.Streamed, ManualAddressing = true, MaxReceivedMessageSize = long.MaxValue, ListenBacklog = maxPending / 2, MaxPendingAccepts = maxPending / 2, MaxPendingConnections = maxPending, PortSharingEnabled = true }; var binding = new CustomBinding(new PqlMessageEncodingBindingElement(), transport) { OpenTimeout = TimeSpan.FromMinutes(1), CloseTimeout = TimeSpan.FromMinutes(1), ReceiveTimeout = TimeSpan.FromMinutes(60), SendTimeout = TimeSpan.FromMinutes(60) }; return(binding); }
private ChannelFactory <IDataService> GetChannelFactory() { if (m_channelFactory == null) { if (string.IsNullOrEmpty(ConnectionString)) { throw new InvalidOperationException("ConnectionString is not set"); } m_connectionProps = new ConnectionProps(ConnectionString); var transport = new TcpTransportBindingElement { HostNameComparisonMode = HostNameComparisonMode.WeakWildcard, TransferMode = TransferMode.Streamed, ManualAddressing = true, MaxReceivedMessageSize = long.MaxValue }; var binding = new CustomBinding( new PqlMessageEncodingBindingElement(), transport) { OpenTimeout = TimeSpan.FromMinutes(1), CloseTimeout = TimeSpan.FromMinutes(1), ReceiveTimeout = TimeSpan.FromMinutes(60), SendTimeout = TimeSpan.FromMinutes(60) }; m_channelFactory = new ChannelFactory <IDataService>(binding); } return(m_channelFactory); }
public static CustomBinding CreateBinding(bool portSharingEnabled, int maxReceivedMessageSize, long maxBufferPoolSize, bool useSslStreamSecurity, bool clientCertificateAuthEnabled, DnsEndpointIdentity endpointIdentity, IssuedSecurityTokenParameters issuedTokenParameters) { TransactionFlowBindingElement transactionFlowBindingElement = new TransactionFlowBindingElement(); BinaryMessageEncodingBindingElement binaryMessageEncodingBindingElement = new BinaryMessageEncodingBindingElement(); binaryMessageEncodingBindingElement.ReaderQuotas.MaxStringContentLength = maxReceivedMessageSize; TcpTransportBindingElement tcpTransportBindingElement = new TcpTransportBindingElement() { PortSharingEnabled = portSharingEnabled, MaxReceivedMessageSize = (long)maxReceivedMessageSize, MaxBufferPoolSize = maxBufferPoolSize }; CustomBinding customBinding = new CustomBinding(); customBinding.Elements.Add(transactionFlowBindingElement); if (useSslStreamSecurity) { SslStreamSecurityBindingElement sslStreamSecurityBindingElement = new SslStreamSecurityBindingElement(); if (endpointIdentity != null) { sslStreamSecurityBindingElement.IdentityVerifier = new LenientDnsIdentityVerifier(endpointIdentity); } sslStreamSecurityBindingElement.RequireClientCertificate = clientCertificateAuthEnabled; customBinding.Elements.Add(sslStreamSecurityBindingElement); } customBinding.Elements.Add(binaryMessageEncodingBindingElement); customBinding.Elements.Add(tcpTransportBindingElement); return(customBinding); }
public void GetPropertySecurityCapabilities() { var b = new TcpTransportBindingElement(); var s = b.GetProperty <ISecurityCapabilities> (new BindingContext(new CustomBinding(), new BindingParameterCollection())); Assert.IsNull(s, "#1"); }
public static void LeaseTimeout_Property_Sets(TimeSpan timeSpan) { // TcpConnectionPoolSettings has no public constructor but we can access it from the TcpTransportBindingElement TcpTransportBindingElement element = new TcpTransportBindingElement(); TcpConnectionPoolSettings settings = element.ConnectionPoolSettings; settings.LeaseTimeout = timeSpan; Assert.Equal<TimeSpan>(timeSpan, settings.LeaseTimeout); }
public static void GroupName_Property_Sets(string groupName) { // TcpConnectionPoolSettings has no public constructor but we can access it from the TcpTransportBindingElement TcpTransportBindingElement element = new TcpTransportBindingElement(); TcpConnectionPoolSettings settings = element.ConnectionPoolSettings; settings.GroupName = groupName; Assert.Equal<string>(groupName, settings.GroupName); }
private static CustomBinding CreateTcpBinding() { CustomBinding binding = new CustomBinding("MetadataExchangeTcpBinding", "http://schemas.microsoft.com/ws/2005/02/mex/bindings", new BindingElement[0]); TcpTransportBindingElement item = new TcpTransportBindingElement(); binding.Elements.Add(item); return(binding); }
private static CustomBinding CreateTcpBinding() { CustomBinding binding = new CustomBinding(MetadataStrings.MetadataExchangeStrings.TcpBindingName, MetadataStrings.MetadataExchangeStrings.BindingNamespace); TcpTransportBindingElement tcpTransport = new TcpTransportBindingElement(); binding.Elements.Add(tcpTransport); return(binding); }
public static void MaxOutboundConnectionsPerEndpoint_Property_Set_Invalid_Value_Throws(int value) { // TcpConnectionPoolSettings has no public constructor but we can access it from the TcpTransportBindingElement TcpTransportBindingElement element = new TcpTransportBindingElement(); TcpConnectionPoolSettings settings = element.ConnectionPoolSettings; Assert.Throws <ArgumentOutOfRangeException>(() => settings.MaxOutboundConnectionsPerEndpoint = value); }
public void GetPrpertyBindingDeliveryCapabilities() { var be = new TcpTransportBindingElement(); var dc = be.GetProperty <IBindingDeliveryCapabilities> (new BindingContext(new CustomBinding(), new BindingParameterCollection())); Assert.IsTrue(dc.AssuresOrderedDelivery, "#1"); Assert.IsFalse(dc.QueuedDelivery, "#2"); }
public static void GroupName_Property_Set_Null_Value_Throws() { // TcpConnectionPoolSettings has no public constructor but we can access it from the TcpTransportBindingElement TcpTransportBindingElement element = new TcpTransportBindingElement(); TcpConnectionPoolSettings settings = element.ConnectionPoolSettings; Assert.Throws <ArgumentNullException>(() => settings.GroupName = null); }
public static void LeaseTimeout_Property_Set_Invalid_Value_Throws(TimeSpan timeSpan) { // TcpConnectionPoolSettings has no public constructor but we can access it from the TcpTransportBindingElement TcpTransportBindingElement element = new TcpTransportBindingElement(); TcpConnectionPoolSettings settings = element.ConnectionPoolSettings; Assert.Throws <ArgumentOutOfRangeException>(() => settings.LeaseTimeout = timeSpan); }
public static void MaxOutboundConnectionsPerEndpoint_Property_Sets(int value) { // TcpConnectionPoolSettings has no public constructor but we can access it from the TcpTransportBindingElement TcpTransportBindingElement element = new TcpTransportBindingElement(); TcpConnectionPoolSettings settings = element.ConnectionPoolSettings; settings.MaxOutboundConnectionsPerEndpoint = value; Assert.Equal<int>(value, settings.MaxOutboundConnectionsPerEndpoint); }
private void Initialize() { this.transport = new TcpTransportBindingElement(); this.encoding = new BinaryMessageEncodingBindingElement(); this.context = GetDefaultTransactionFlowBindingElement(); this.session = new ReliableSessionBindingElement(); this.reliableSession = new OptionalReliableSession(this.session); }
void Initialize() { be = new ChunkingBindingElement(); tcpbe = new TcpTransportBindingElement(); tcpbe.TransferMode=TransferMode.Buffered; //no transport streaming tcpbe.MaxReceivedMessageSize = ChunkingUtils.ChunkSize + 100 * 1024; //add 100KB for headers this.SendTimeout = new TimeSpan(0, 5, 0); this.ReceiveTimeout = this.SendTimeout; }
private void Initialize() { _transport = new TcpTransportBindingElement(); _encoding = new BinaryMessageEncodingBindingElement(); // NetNative and CoreCLR initialize to what TransportBindingElement does in the desktop // This property is not available in shipped contracts _maxBufferPoolSize = TransportDefaults.MaxBufferPoolSize; }
public static void GroupName_Property_Sets(string groupName) { // TcpConnectionPoolSettings has no public constructor but we can access it from the TcpTransportBindingElement TcpTransportBindingElement element = new TcpTransportBindingElement(); TcpConnectionPoolSettings settings = element.ConnectionPoolSettings; settings.GroupName = groupName; Assert.Equal(groupName, settings.GroupName); }
public TcpChannelFactory(TcpTransportBindingElement bindingElement, BindingContext context) : base(bindingElement, context, bindingElement.ConnectionPoolSettings.GroupName, bindingElement.ConnectionPoolSettings.IdleTimeout, bindingElement.ConnectionPoolSettings.MaxOutboundConnectionsPerEndpoint, true) { LeaseTimeout = bindingElement.ConnectionPoolSettings.LeaseTimeout; }
void Initialize() { be = new ChunkingBindingElement(); tcpbe = new TcpTransportBindingElement(); tcpbe.TransferMode = TransferMode.Buffered; //no transport streaming tcpbe.MaxReceivedMessageSize = ChunkingUtils.ChunkSize + 100 * 1024; //add 100KB for headers this.SendTimeout = new TimeSpan(0, 5, 0); this.ReceiveTimeout = this.SendTimeout; }
public static void MaxOutboundConnectionsPerEndpoint_Property_Sets(int value) { // TcpConnectionPoolSettings has no public constructor but we can access it from the TcpTransportBindingElement TcpTransportBindingElement element = new TcpTransportBindingElement(); TcpConnectionPoolSettings settings = element.ConnectionPoolSettings; settings.MaxOutboundConnectionsPerEndpoint = value; Assert.Equal <int>(value, settings.MaxOutboundConnectionsPerEndpoint); }
public static void LeaseTimeout_Property_Sets(TimeSpan timeSpan) { // TcpConnectionPoolSettings has no public constructor but we can access it from the TcpTransportBindingElement TcpTransportBindingElement element = new TcpTransportBindingElement(); TcpConnectionPoolSettings settings = element.ConnectionPoolSettings; settings.LeaseTimeout = timeSpan; Assert.Equal <TimeSpan>(timeSpan, settings.LeaseTimeout); }
/// <summary> /// Initializes the binding. /// </summary> /// <param name="namespaceUris">The namespace uris.</param> /// <param name="factory">The factory.</param> /// <param name="configuration">The configuration.</param> /// <param name="descriptions">The descriptions.</param> public UaTcpBinding( NamespaceTable namespaceUris, EncodeableFactory factory, EndpointConfiguration configuration, params EndpointDescription[] descriptions) : base(namespaceUris, factory, configuration) { m_transport = new TcpTransportBindingElement(); m_transport.MaxReceivedMessageSize = configuration.MaxMessageSize; }
public static void Ctor_Default_Properties() { // Validates new TcpTransportBindingElement() initializes correct default property values TcpTransportBindingElement element = new TcpTransportBindingElement(); Assert.True(String.Equals(element.Scheme, "net.tcp"), String.Format("Scheme property expected '{0}' but actual was '{1}'", "net.tcp", element.Scheme)); // Validate only a non-null TcpConnectionPoolSetting. // Its own default values are validated in that type's test methods Assert.True(element.ConnectionPoolSettings != null, "ConnectionPoolSettings should not be null."); }
private static void AddMexEndpointMetadata(ServiceHost host) { var tcpBinding = new TcpTransportBindingElement(); var customBinding = new CustomBinding(tcpBinding); // validate whether ServiceMetadataBehavior is present var metaDataBehavior = host.Description.Behaviors.Find<ServiceMetadataBehavior>(); if (metaDataBehavior == null) { metaDataBehavior = new ServiceMetadataBehavior(); host.Description.Behaviors.Add(metaDataBehavior); } host.AddServiceEndpoint(typeof(IMetadataExchange), customBinding, "MEX"); }
public static ServiceEndpoint[] GetEndpoints(string mexAddress) { var address = new Uri(mexAddress); ServiceEndpointCollection endpoints = null; if (address.Scheme == "net.tcp") { var tcpBindingElement = new TcpTransportBindingElement(); tcpBindingElement.MaxReceivedMessageSize *= MessageMultiplier; endpoints = QueryMexEndpoint(mexAddress, tcpBindingElement); } if (address.Scheme == "net.pipe") { } if (address.Scheme == "http") { } if (address.Scheme == "https") { } return endpoints.ToArray(); }
public FileDownloadService() { TcpTransportBindingElement transport = new TcpTransportBindingElement(); transport.MaxReceivedMessageSize = long.MaxValue; transport.MaxBufferSize = int.MaxValue; transport.MaxBufferPoolSize = long.MaxValue; transport.TransferMode = TransferMode.Streamed; BinaryMessageEncodingBindingElement encoder = new BinaryMessageEncodingBindingElement(); CustomBinding binding = new CustomBinding(encoder, transport); binding.ReceiveTimeout = TimeSpan.MaxValue; binding.SendTimeout = TimeSpan.MaxValue; binding.CloseTimeout = TimeSpan.MaxValue; serviceHost = new ServiceHost(this); serviceHost.AddServiceEndpoint(typeof(IFileDownloadService), binding, "net.tcp://localhost:8020"); serviceHost.Open(); }
public static void SetBindingProperties(this Binding binding, ServiceConfig bindingProperties) { if (binding.GetType().Equals(typeof(System.ServiceModel.NetTcpBinding))) { //(binding as System.ServiceModel.NetTcpBinding).Security.Message.ClientCredentialType = bindingProperties.MessageCredentialType; //(binding as System.ServiceModel.NetTcpBinding).Security.Transport.ClientCredentialType = bindingProperties.TcpClientCredentialType; //(binding as System.ServiceModel.NetTcpBinding).Security.Transport.ProtectionLevel = bindingProperties.ProtectionLevel; (binding as System.ServiceModel.NetTcpBinding).MaxConnections = bindingProperties.NetParameter.MaxConnections; (binding as System.ServiceModel.NetTcpBinding).MaxReceivedMessageSize = bindingProperties.NetParameter.MaxReceivedMessageSize; (binding as System.ServiceModel.NetTcpBinding).MaxBufferPoolSize = bindingProperties.NetParameter.MaxBufferPoolSize; (binding as System.ServiceModel.NetTcpBinding).ReaderQuotas.MaxArrayLength = bindingProperties.NetParameter.MaxArrayLength; (binding as System.ServiceModel.NetTcpBinding).ReaderQuotas.MaxBytesPerRead = bindingProperties.NetParameter.MaxBytesPerRead; (binding as System.ServiceModel.NetTcpBinding).ReaderQuotas.MaxDepth = bindingProperties.NetParameter.MaxDepth; (binding as System.ServiceModel.NetTcpBinding).ReaderQuotas.MaxStringContentLength = bindingProperties.NetParameter.MaxStringContentLength; (binding as System.ServiceModel.NetTcpBinding).ReaderQuotas.MaxNameTableCharCount = bindingProperties.NetParameter.MaxNameTableCharCount; } //not allowed by partially trusted //tcpBinding.MaxBufferSize = 262144; //256KB default is 65,536 bytes binding.OpenTimeout = TimeSpan.FromSeconds(bindingProperties.NetParameter.OpenTimeout); binding.CloseTimeout = TimeSpan.FromSeconds(bindingProperties.NetParameter.CloseTimeout); binding.ReceiveTimeout = TimeSpan.FromSeconds(bindingProperties.NetParameter.ReceiveTimeout); binding.SendTimeout = TimeSpan.FromSeconds(bindingProperties.NetParameter.SendTimeout); CustomBinding cb = new CustomBinding(binding); TcpTransportBindingElement tcpe = new TcpTransportBindingElement(); tcpe.ConnectionBufferSize = bindingProperties.NetParameter.ConnectionBufferSize; tcpe.ConnectionPoolSettings.LeaseTimeout = TimeSpan.FromSeconds(bindingProperties.NetParameter.ConnectionLeaseTimeout); tcpe.ConnectionPoolSettings.IdleTimeout = TimeSpan.FromSeconds(bindingProperties.NetParameter.IdleTimeout); tcpe.ListenBacklog = bindingProperties.NetParameter.ListenBacklog; tcpe.ConnectionPoolSettings.MaxOutboundConnectionsPerEndpoint = bindingProperties.NetParameter.MaxOutboundConnectionsPerEndpoint; tcpe.MaxOutputDelay = TimeSpan.FromSeconds(bindingProperties.NetParameter.MaxOutputDelay); tcpe.MaxPendingAccepts = bindingProperties.NetParameter.MaxPendingAccepts; tcpe.MaxPendingConnections = bindingProperties.NetParameter.MaxPendingConnections; cb.Elements.Add(tcpe); binding = cb; }
public static void Main () { Console.WriteLine ("WARNING!! This test is not configured enought to work fine on .NET either."); SymmetricSecurityBindingElement sbe = new SymmetricSecurityBindingElement (); sbe.MessageSecurityVersion = MessageSecurityVersion.WSSecurity11WSTrustFebruary2005WSSecureConversationFebruary2005WSSecurityPolicy11BasicSecurityProfile10; sbe.RequireSignatureConfirmation = true; //sbe.IncludeTimestamp = false; sbe.ProtectionTokenParameters = new X509SecurityTokenParameters (X509KeyIdentifierClauseType.Thumbprint, SecurityTokenInclusionMode.Never); X509SecurityTokenParameters p = new X509SecurityTokenParameters (X509KeyIdentifierClauseType.Thumbprint, SecurityTokenInclusionMode.AlwaysToRecipient); p.RequireDerivedKeys = false; sbe.EndpointSupportingTokenParameters.Endorsing.Add (p); //sbe.SetKeyDerivation (false); //sbe.MessageProtectionOrder = MessageProtectionOrder.SignBeforeEncrypt; ServiceHost host = new ServiceHost (typeof (Foo)); var mbe = new BinaryMessageEncodingBindingElement (); var tbe = new TcpTransportBindingElement (); CustomBinding binding = new CustomBinding (sbe, mbe, tbe); binding.ReceiveTimeout = TimeSpan.FromSeconds (5); host.AddServiceEndpoint ("IFoo", binding, new Uri ("http://localhost:8080")); ServiceCredentials cred = new ServiceCredentials (); cred.ServiceCertificate.Certificate = new X509Certificate2 ("test.pfx", "mono"); cred.ClientCertificate.Authentication.CertificateValidationMode = X509CertificateValidationMode.None; host.Description.Behaviors.Add (cred); host.Description.Behaviors.Find<ServiceDebugBehavior> () .IncludeExceptionDetailInFaults = true; ServiceMetadataBehavior smb = new ServiceMetadataBehavior (); smb.HttpGetEnabled = true; smb.HttpGetUrl = new Uri ("http://localhost:8080/wsdl"); host.Description.Behaviors.Add (smb); host.Open (); Console.WriteLine ("Hit [CR] key to close ..."); Console.ReadLine (); host.Close (); }
/// <summary> /// Initializes the binding. /// </summary> /// <param name="namespaceUris">The namespace uris.</param> /// <param name="factory">The factory.</param> /// <param name="configuration">The configuration.</param> /// <param name="description">The description.</param> public UaSoapXmlOverTcpBinding( NamespaceTable namespaceUris, EncodeableFactory factory, EndpointConfiguration configuration, EndpointDescription description) : base(namespaceUris, factory, configuration) { if (description != null && description.SecurityMode != MessageSecurityMode.None) { TransportSecurityBindingElement bootstrap = SecurityBindingElement.CreateUserNameOverTransportBindingElement(); bootstrap.IncludeTimestamp = true; bootstrap.MessageSecurityVersion = MessageSecurityVersion.WSSecurity11WSTrustFebruary2005WSSecureConversationFebruary2005WSSecurityPolicy11BasicSecurityProfile10; bootstrap.SecurityHeaderLayout = SecurityHeaderLayout.Strict; m_security = SecurityBindingElement.CreateSecureConversationBindingElement(bootstrap); m_security.IncludeTimestamp = true; m_security.MessageSecurityVersion = MessageSecurityVersion.WSSecurity11WSTrustFebruary2005WSSecureConversationFebruary2005WSSecurityPolicy11BasicSecurityProfile10; m_security.SecurityHeaderLayout = SecurityHeaderLayout.Strict; } m_encoding = new BinaryMessageEncodingBindingElement(); // WCF does not distinguish between arrays and byte string. int maxArrayLength = configuration.MaxArrayLength; if (configuration.MaxArrayLength < configuration.MaxByteStringLength) { maxArrayLength = configuration.MaxByteStringLength; } m_encoding.ReaderQuotas.MaxArrayLength = maxArrayLength; m_encoding.ReaderQuotas.MaxStringContentLength = configuration.MaxStringLength; m_encoding.ReaderQuotas.MaxBytesPerRead = Int32.MaxValue; m_encoding.ReaderQuotas.MaxDepth = Int32.MaxValue; m_encoding.ReaderQuotas.MaxNameTableCharCount = Int32.MaxValue; m_transport = new TcpTransportBindingElement(); m_transport.ManualAddressing = false; m_transport.MaxReceivedMessageSize = configuration.MaxMessageSize; }
static void Main(string[] args) { NetTcpBinding bind = new NetTcpBinding(); Uri uri = new Uri(ConfigurationManager.AppSettings["conAddress"]);//从配置文件中读取服务的Url ServiceHost host = new ServiceHost(typeof(WCFChatService.ChatService), uri); //if中的代码可以没有,但是如果想利用Svctuil.exe生成代理类的时候,就需要下面的代码,否则将会报错,无法解析元数据 if (host.Description.Behaviors.Find<System.ServiceModel.Description.ServiceMetadataBehavior>() == null) { BindingElement metaElement = new TcpTransportBindingElement(); CustomBinding metaBind = new CustomBinding(metaElement); host.Description.Behaviors.Add(new System.ServiceModel.Description.ServiceMetadataBehavior()); host.AddServiceEndpoint(typeof(System.ServiceModel.Description.IMetadataExchange), metaBind, "MEX"); } host.Open(); Console.WriteLine("聊天室服务器开始监听: endpoint {0}", uri.ToString()); Console.WriteLine("按 ENTER 停止服务器监听..."); Console.ReadLine(); host.Abort(); host.Close(); }
public void CanBuildChannelFactory () { TcpTransportBindingElement be = new TcpTransportBindingElement (); BindingContext ctx = new BindingContext ( new CustomBinding (), empty_params); Assert.IsFalse (be.CanBuildChannelFactory<IRequestChannel> (ctx), "#1"); Assert.IsFalse (be.CanBuildChannelFactory<IInputChannel> (ctx), "#2"); Assert.IsFalse (be.CanBuildChannelFactory<IReplyChannel> (ctx), "#3"); Assert.IsFalse (be.CanBuildChannelFactory<IOutputChannel> (ctx), "#4"); Assert.IsFalse (be.CanBuildChannelFactory<IRequestSessionChannel> (ctx), "#5"); Assert.IsFalse (be.CanBuildChannelFactory<IInputSessionChannel> (ctx), "#6"); Assert.IsFalse (be.CanBuildChannelFactory<IReplySessionChannel> (ctx), "#7"); Assert.IsFalse (be.CanBuildChannelFactory<IOutputSessionChannel> (ctx), "#8"); // IServiceChannel is not supported Assert.IsFalse (be.CanBuildChannelFactory<IServiceChannel> (ctx), "#9"); Assert.IsFalse (be.CanBuildChannelFactory<IClientChannel> (ctx), "#10"); Assert.IsFalse (be.CanBuildChannelFactory<IDuplexChannel> (ctx), "#11"); Assert.IsTrue (be.CanBuildChannelFactory<IDuplexSessionChannel> (ctx), "#12"); }
public static void SameBinding_SecurityModeNone_Text_EchoString_Roundtrip() { BindingElement[] bindingElements = null; CustomBinding binding = null; ChannelFactory<IWcfService> factory = null; IWcfService serviceProxy = null; EndpointAddress endpointAddress = null; string result = null; string testString = "Hello"; try { // *** SETUP *** \\ bindingElements = new BindingElement[2]; bindingElements[0] = new TextMessageEncodingBindingElement(); bindingElements[1] = new TcpTransportBindingElement(); binding = new CustomBinding(bindingElements); endpointAddress = new EndpointAddress(Endpoints.Tcp_CustomBinding_NoSecurity_Text_Address); factory = new ChannelFactory<IWcfService>(binding, endpointAddress); serviceProxy = factory.CreateChannel(); // *** EXECUTE *** \\ result = serviceProxy.Echo(testString); // *** VALIDATE *** \\ Assert.True(String.Equals(result, testString), String.Format(" Error: expected response from service: '{0}' Actual was: '{1}'", testString, result)); // *** CLEANUP *** \\ factory.Close(); ((ICommunicationObject)serviceProxy).Close(); } finally { // *** ENSURE CLEANUP *** \\ ScenarioTestHelpers.CloseCommunicationObjects((ICommunicationObject)serviceProxy, factory); } }
public static ServiceEndpointCollection GetEndpoints(string mexAddress) { Uri mexUri = new Uri(mexAddress); TransportBindingElement transportElement; switch (mexUri.Scheme) { case "net.tcp": transportElement = new TcpTransportBindingElement(); break; case "net.pipe": transportElement = new NamedPipeTransportBindingElement(); break; case "http": transportElement = new HttpTransportBindingElement(); break; case "https": transportElement = new HttpsTransportBindingElement(); break; default: throw new NotSupportedException("Scheme not supported."); } transportElement.MaxReceivedMessageSize *= MessageSizeMultiplier; return GetEndpoints(mexUri, transportElement); ; }
public void DefaultValues () { TcpTransportBindingElement be = new TcpTransportBindingElement (); Assert.AreEqual (TimeSpan.FromSeconds (5), be.ChannelInitializationTimeout, "#1"); Assert.AreEqual (0x2000, be.ConnectionBufferSize, "#2"); Assert.AreEqual (HostNameComparisonMode.StrongWildcard, be.HostNameComparisonMode, "#3"); Assert.AreEqual (0x10000, be.MaxBufferSize, "#4"); Assert.AreEqual (TimeSpan.FromMilliseconds (200), be.MaxOutputDelay, "#5"); Assert.AreEqual (1, be.MaxPendingAccepts, "#6"); Assert.AreEqual (10, be.MaxPendingConnections, "#7"); Assert.AreEqual (TransferMode.Buffered, be.TransferMode, "#8"); Assert.AreEqual (10, be.ListenBacklog, "#9"); Assert.IsFalse (be.PortSharingEnabled, "#10"); Assert.AreEqual ("net.tcp", be.Scheme, "#11"); Assert.IsFalse (be.TeredoEnabled, "#12"); TcpConnectionPoolSettings pool = be.ConnectionPoolSettings; Assert.IsNotNull (pool, "#13"); Assert.AreEqual ("default", pool.GroupName, "#14"); Assert.AreEqual (TimeSpan.FromSeconds (120), pool.IdleTimeout, "#15"); Assert.AreEqual (TimeSpan.FromSeconds (300), pool.LeaseTimeout, "#16"); Assert.AreEqual (10, pool.MaxOutboundConnectionsPerEndpoint, "#17"); }
public static void SameBinding_SecurityModeNone_Text_EchoString_Roundtrip() { string variationDetails = "Client:: CustomBinding/TcpTransport/NoWindowsStreamSecurity/TextMessageEncoding = None\nServer:: CustomBinding/TcpTransport/NoWindowsStreamSecurity/TextMessageEncoding = None"; string testString = "Hello"; StringBuilder errorBuilder = new StringBuilder(); bool success = false; try { BindingElement[] bindingElements = new BindingElement[2]; bindingElements[0] = new TextMessageEncodingBindingElement(); bindingElements[1] = new TcpTransportBindingElement(); CustomBinding binding = new CustomBinding(bindingElements); ChannelFactory<IWcfService> factory = new ChannelFactory<IWcfService>(binding, new EndpointAddress(Endpoints.Tcp_CustomBinding_NoSecurity_Text_Address)); IWcfService serviceProxy = factory.CreateChannel(); string result = serviceProxy.Echo(testString); success = string.Equals(result, testString); if (!success) { errorBuilder.AppendLine(String.Format(" Error: expected response from service: '{0}' Actual was: '{1}'", testString, result)); } } catch (Exception ex) { errorBuilder.AppendLine(String.Format(" Error: Unexpected exception was caught while doing the basic echo test for variation...\n'{0}'\nException: {1}", variationDetails, ex.ToString())); for (Exception innerException = ex.InnerException; innerException != null; innerException = innerException.InnerException) { errorBuilder.AppendLine(String.Format("Inner exception: {0}", innerException.ToString())); } } Assert.True(errorBuilder.Length == 0, "Test case FAILED with errors: " + errorBuilder.ToString()); }
public static ServiceEndpoint[] GetEndpoints(string mexAddress) { if (String.IsNullOrEmpty(mexAddress)) { Debug.Assert(false, "Empty address"); return null; } Uri address = new Uri(mexAddress); ServiceEndpointCollection endpoints = null; if (address.Scheme == "http") { HttpTransportBindingElement httpBindingElement = new HttpTransportBindingElement(); httpBindingElement.MaxReceivedMessageSize *= MessageSizeMultiplier; //Try the HTTP MEX Endpoint try { endpoints = QueryMexEndpoint(mexAddress, httpBindingElement); } catch { } //Try over HTTP-GET if (endpoints == null) { string httpGetAddress = mexAddress; if (mexAddress.EndsWith("?wsdl") == false) { httpGetAddress += "?wsdl"; } CustomBinding binding = new CustomBinding(httpBindingElement); MetadataExchangeClient mexClient = new MetadataExchangeClient(binding); MetadataSet metadata = mexClient.GetMetadata(new Uri(httpGetAddress), MetadataExchangeClientMode.HttpGet); MetadataImporter importer = new WsdlImporter(metadata); endpoints = importer.ImportAllEndpoints(); } } if (address.Scheme == "https") { HttpsTransportBindingElement httpsBindingElement = new HttpsTransportBindingElement(); httpsBindingElement.MaxReceivedMessageSize *= MessageSizeMultiplier; //Try the HTTPS MEX Endpoint try { endpoints = QueryMexEndpoint(mexAddress, httpsBindingElement); } catch { } //Try over HTTPS-GET if (endpoints == null) { string httpsGetAddress = mexAddress; if (mexAddress.EndsWith("?wsdl") == false) { httpsGetAddress += "?wsdl"; } CustomBinding binding = new CustomBinding(httpsBindingElement); MetadataExchangeClient mexClient = new MetadataExchangeClient(binding); MetadataSet metadata = mexClient.GetMetadata(new Uri(httpsGetAddress), MetadataExchangeClientMode.HttpGet); MetadataImporter importer = new WsdlImporter(metadata); endpoints = importer.ImportAllEndpoints(); } } if (address.Scheme == "net.tcp") { TcpTransportBindingElement tcpBindingElement = new TcpTransportBindingElement(); tcpBindingElement.MaxReceivedMessageSize *= MessageSizeMultiplier; endpoints = QueryMexEndpoint(mexAddress, tcpBindingElement); } if (address.Scheme == "net.pipe") { NamedPipeTransportBindingElement ipcBindingElement = new NamedPipeTransportBindingElement(); ipcBindingElement.MaxReceivedMessageSize *= MessageSizeMultiplier; endpoints = QueryMexEndpoint(mexAddress, ipcBindingElement); } return endpoints.ToArray(); }
public static ServiceEndpoint[] GetEndpoints(string mexAddress) { if(string.IsNullOrWhiteSpace(mexAddress)) { throw new ArgumentException("mexAddress"); } Uri address = new Uri(mexAddress); ServiceEndpointCollection endpoints = null; BindingElement bindingElement = null; //Try over HTTP-GET first if(address.Scheme == Uri.UriSchemeHttp || address.Scheme == Uri.UriSchemeHttps) { string getAddress = mexAddress; if(mexAddress.EndsWith("?wsdl") == false) { getAddress += "?wsdl"; } if(address.Scheme == Uri.UriSchemeHttp) { HttpTransportBindingElement httpBindingElement = new HttpTransportBindingElement(); httpBindingElement.MaxReceivedMessageSize *= MessageSizeMultiplier; bindingElement = httpBindingElement; } else { HttpsTransportBindingElement httpsBindingElement = new HttpsTransportBindingElement(); httpsBindingElement.MaxReceivedMessageSize *= MessageSizeMultiplier; bindingElement = httpsBindingElement; } CustomBinding binding = new CustomBinding(bindingElement); MetadataExchangeClient mexClient = new MetadataExchangeClient(binding); MetadataSet metadata = mexClient.GetMetadata(new Uri(getAddress),MetadataExchangeClientMode.HttpGet); MetadataImporter importer = new WsdlImporter(metadata); endpoints = importer.ImportAllEndpoints(); return endpoints.ToArray(); } //Try MEX endpoint: if(address.Scheme == Uri.UriSchemeHttp) { bindingElement = new HttpTransportBindingElement(); } if(address.Scheme == Uri.UriSchemeHttps) { bindingElement = new HttpsTransportBindingElement(); } if(address.Scheme == Uri.UriSchemeNetTcp) { bindingElement = new TcpTransportBindingElement(); } if(address.Scheme == Uri.UriSchemeNetPipe) { bindingElement = new NamedPipeTransportBindingElement(); } endpoints = QueryMexEndpoint(mexAddress,bindingElement); return endpoints.ToArray(); }
// check that properties of the HttpTransportBindingElement and // MessageEncodingBindingElement not exposed as properties on BasicHttpBinding // match default values of the binding elements private bool IsBindingElementsMatch(TcpTransportBindingElement transport, BinaryMessageEncodingBindingElement encoding) { if (!_transport.IsMatch(transport)) return false; if (!_encoding.IsMatch(encoding)) return false; return true; }
public void CanBuildChannelFactory () { // with HttpTransport var m = new WebMessageEncodingBindingElement (); Assert.IsTrue (m.CanBuildChannelFactory<IRequestChannel> (CreateBindingContext ()), "#1"); Assert.IsFalse (m.CanBuildChannelFactory<IReplyChannel> (CreateBindingContext ()), "#2"); Assert.IsFalse (m.CanBuildChannelFactory<IRequestSessionChannel> (CreateBindingContext ()), "#3"); Assert.IsFalse (m.CanBuildChannelFactory<IDuplexChannel> (CreateBindingContext ()), "#4"); // actually they are from transport var h = new HttpTransportBindingElement (); Assert.IsTrue (h.CanBuildChannelFactory<IRequestChannel> (CreateBindingContext ()), "#5"); Assert.IsFalse (h.CanBuildChannelFactory<IReplyChannel> (CreateBindingContext ()), "#6"); Assert.IsFalse (h.CanBuildChannelFactory<IRequestSessionChannel> (CreateBindingContext ()), "#7"); Assert.IsFalse (h.CanBuildChannelFactory<IDuplexChannel> (CreateBindingContext ()), "#8"); // with TcpTransport Assert.IsFalse (m.CanBuildChannelFactory<IRequestChannel> (CreateBindingContext2 ()), "#9"); Assert.IsFalse (m.CanBuildChannelFactory<IReplyChannel> (CreateBindingContext2 ()), "#10"); Assert.IsFalse (m.CanBuildChannelFactory<IRequestSessionChannel> (CreateBindingContext2 ()), "#11"); Assert.IsFalse (m.CanBuildChannelFactory<IDuplexChannel> (CreateBindingContext2 ()), "#12"); // ... yes, actually they are from transport var t = new TcpTransportBindingElement (); Assert.IsFalse (t.CanBuildChannelFactory<IRequestChannel> (CreateBindingContext2 ()), "#13"); Assert.IsFalse (t.CanBuildChannelFactory<IReplyChannel> (CreateBindingContext2 ()), "#14"); Assert.IsFalse (t.CanBuildChannelFactory<IRequestSessionChannel> (CreateBindingContext2 ()), "#15"); Assert.IsFalse (t.CanBuildChannelFactory<IDuplexChannel> (CreateBindingContext2 ()), "#16"); }