/// <summary> /// Initializes the WCF host. /// </summary> private void InitWCFHost() { if (_service != null) { QuitService(); } var address = $"net.tcp://localhost:{_port}/"; _service = new ServiceHost(typeof(WCFServerService), new Uri[] { new Uri(address) }); WCFServerService.Player = _player; var binding = new NetTcpContextBinding(SecurityMode.None) { ReceiveTimeout = new TimeSpan(1, 0, 0), SendTimeout = new TimeSpan(0, 1, 0) }; _service.AddServiceEndpoint(typeof(IServerContract), binding, address); _service.Open(); _serverInfo = new ServerInfo { Clients = new Dictionary <string, int>(), IsHost = true, Port = _port }; WCFServerService.ClientConnected += WCFServerService_ClientConnected; WCFServerService.ClientDisconnected += WCFServerService_ClientDisconnected; }
public ServiceHost CreateServiceHost(IBrightstarService service, int httpPort, int tcpPort, string pipeName) { var serviceHost = new ServiceHost(service, new[] { new Uri(string.Format("http://localhost:{0}/brightstar", httpPort)), new Uri(string.Format("net.tcp://localhost:{0}/brightstar", tcpPort)), new Uri(string.Format("net.pipe://localhost/{0}", pipeName)) }); var basicHttpBinding = new BasicHttpContextBinding { TransferMode = TransferMode.StreamedResponse, MaxReceivedMessageSize = int.MaxValue, SendTimeout = TimeSpan.FromMinutes(30), ReaderQuotas = XmlDictionaryReaderQuotas.Max, Namespace = "http://www.networkedplanet.com/schemas/brightstar" }; var netTcpContextBinding = new NetTcpContextBinding { TransferMode = TransferMode.StreamedResponse, MaxReceivedMessageSize = int.MaxValue, SendTimeout = TimeSpan.FromMinutes(30), ReaderQuotas = XmlDictionaryReaderQuotas.Max, Namespace = "http://www.networkedplanet.com/schemas/brightstar" }; var netNamedPipeBinding = new NetNamedPipeBinding { TransferMode = TransferMode.StreamedResponse, MaxReceivedMessageSize = int.MaxValue, SendTimeout = TimeSpan.FromMinutes(30), ReaderQuotas = XmlDictionaryReaderQuotas.Max, Namespace = "http://www.networkedplanet.com/schemas/brightstar" }; serviceHost.AddServiceEndpoint(typeof(IBrightstarService), basicHttpBinding, ""); serviceHost.AddServiceEndpoint(typeof(IBrightstarService), netTcpContextBinding, ""); serviceHost.AddServiceEndpoint(typeof(IBrightstarService), netNamedPipeBinding, ""); var throttlingBehavior = new ServiceThrottlingBehavior { MaxConcurrentCalls = int.MaxValue }; serviceHost.Description.Behaviors.Add(new ServiceMetadataBehavior { HttpGetEnabled = true }); serviceHost.Description.Behaviors.Add(throttlingBehavior); return(serviceHost); }
protected override void OnApplyConfiguration(Binding binding) { base.OnApplyConfiguration(binding); NetTcpContextBinding netTcpContextBinding = (NetTcpContextBinding)binding; netTcpContextBinding.ClientCallbackAddress = this.ClientCallbackAddress; netTcpContextBinding.ContextManagementEnabled = this.ContextManagementEnabled; netTcpContextBinding.ContextProtectionLevel = this.ContextProtectionLevel; }
protected internal override void InitializeFrom(Binding binding) { base.InitializeFrom(binding); NetTcpContextBinding netTcpContextBinding = (NetTcpContextBinding)binding; SetPropertyValueIfNotDefaultValue(ConfigurationStrings.ClientCallbackAddressName, netTcpContextBinding.ClientCallbackAddress); SetPropertyValueIfNotDefaultValue(NetTcpContextBindingElement.ContextManagementEnabledName, netTcpContextBinding.ContextManagementEnabled); SetPropertyValueIfNotDefaultValue(NetTcpContextBindingElement.ContextProtectionLevelName, netTcpContextBinding.ContextProtectionLevel); }
public static Binding WcfBindingFactory(string bindingtype, string bidingconfigname) { Binding binding = null; if (!string.IsNullOrEmpty(bindingtype) && !string.IsNullOrEmpty(bidingconfigname)) { switch (bindingtype) { case "basicHttpBinding": binding = new BasicHttpBinding(bidingconfigname); break; case "basicHttpContextBinding": binding = new BasicHttpContextBinding(bidingconfigname); break; case "wsHttpBinding": binding = new WSHttpBinding(bidingconfigname); break; case "wsHttpContextBinding": binding = new WSHttpContextBinding(bidingconfigname); break; case "netTcpBinding": binding = new NetTcpBinding(bidingconfigname); break; case "netTcpContextBinding": binding = new NetTcpContextBinding(bidingconfigname); break; case "netPeerTcpBinding": binding = new NetPeerTcpBinding(bidingconfigname); break; case "netNamedPipeBinding": binding = new NetNamedPipeBinding(bidingconfigname); break; case "webHttpBinding": binding = new WSHttpBinding(bidingconfigname); break; case "wsDualHttpBinding": binding = new WSDualHttpBinding(bidingconfigname); break; case "customBinding": binding = new CustomBinding(bidingconfigname); break; } } return(binding); }
protected internal override void InitializeFrom(Binding binding) { base.InitializeFrom(binding); NetTcpContextBinding binding2 = (NetTcpContextBinding)binding; this.ClientCallbackAddress = binding2.ClientCallbackAddress; if (!binding2.ContextManagementEnabled) { this.ContextManagementEnabled = binding2.ContextManagementEnabled; } this.ContextProtectionLevel = binding2.ContextProtectionLevel; }
/// <summary> /// Create a connection to a musicplayer server. /// </summary> /// <param name="player">The musicplayer.</param> /// <param name="address">The server ip address.</param> /// <param name="port">The server port.</param> public ClientConnection(IMusicPlayer player, IPAddress address, int port) : base(player) { _client = new WCFServerClient(this); string serviceAddress = $"net.tcp://{address.ToString()}:{port}/"; NetTcpContextBinding binding = new NetTcpContextBinding(SecurityMode.None); binding.CloseTimeout = new TimeSpan(0, 1, 0); binding.ReceiveTimeout = new TimeSpan(1, 0, 0); binding.SendTimeout = new TimeSpan(0, 1, 0); binding.MaxReceivedMessageSize = 100000000; // 100Mb _factory = new DuplexChannelFactory <IServerContract>(new InstanceContext(_client), binding, serviceAddress); _server = _factory.CreateChannel(); _server.Anounce(); }
/// <summary> /// Initialises and returns a new NetTcp service client. This client should be used when the client is on a separate machine from the service. /// </summary> /// <param name="endpointUri">The uri where the NetTcp endpoint is running. By default this is net.tcp://{machinename}:8095/brightstar</param> /// <param name="queryCache">OPTIONAL : the cache to use for query results</param> /// <returns>A new brightstar service client. It is important to call dispose on the client after use.</returns> internal static IBrightstarService GetNetTcpClient(Uri endpointUri, ICache queryCache = null) { var binding = new NetTcpContextBinding { MaxReceivedMessageSize = Int32.MaxValue, SendTimeout = TimeSpan.FromMinutes(30), TransferMode = TransferMode.StreamedResponse, ReaderQuotas = XmlDictionaryReaderQuotas.Max }; var endpointAddress = new EndpointAddress(endpointUri); var client = new BrightstarServiceClient(new BrightstarWcfServiceClient(binding, endpointAddress), queryCache); return(client); }
private static Binding GetNetTcpContextBinding() { var binding = new NetTcpContextBinding(); binding.MaxReceivedMessageSize = int.MaxValue; binding.Security.Mode = SecurityMode.None; binding.Security.Message.ClientCredentialType = MessageCredentialType.None; binding.TransferMode = TransferMode.Buffered; binding.ListenBacklog = int.MaxValue; binding.MaxConnections = short.MaxValue; binding.ReaderQuotas.MaxDepth = int.MaxValue; binding.ReaderQuotas.MaxStringContentLength = int.MaxValue; binding.ReaderQuotas.MaxArrayLength = int.MaxValue; binding.ReaderQuotas.MaxBytesPerRead = int.MaxValue; binding.ReaderQuotas.MaxNameTableCharCount = int.MaxValue; return(binding); }
public void ImportEndpoint(WsdlImporter importer, WsdlEndpointConversionContext context) { if (context == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("context"); } if (context.Endpoint == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("context.Endpoint"); } if (context.Endpoint.Binding == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("context.Endpoint.Binding"); } // Try to post-process the unrecognized RequireHttpCookie assertion to augment the AllowCookies value // of HttpTransportBindingElement CustomBinding customBinding = context.Endpoint.Binding as CustomBinding; if (customBinding != null) { UnrecognizedAssertionsBindingElement unrecognized = null; unrecognized = customBinding.Elements.Find <UnrecognizedAssertionsBindingElement>(); HttpTransportBindingElement http = null; if (unrecognized != null) { XmlElement httpUseCookieAssertion = null; if (ContextBindingElementPolicy.TryGetHttpUseCookieAssertion(unrecognized.BindingAsserions, out httpUseCookieAssertion)) { foreach (BindingElement element in customBinding.Elements) { http = element as HttpTransportBindingElement; if (http != null) { http.AllowCookies = true; unrecognized.BindingAsserions.Remove(httpUseCookieAssertion); if (unrecognized.BindingAsserions.Count == 0) { customBinding.Elements.Remove(unrecognized); } break; } } } } // Try to upgrade to standard binding BindingElementCollection bindingElements = customBinding.CreateBindingElements(); Binding binding; if (!WSHttpContextBinding.TryCreate(bindingElements, out binding) && !NetTcpContextBinding.TryCreate(bindingElements, out binding)) { // Work around BasicHttpBinding.TryCreate insensitivity to HttpTransportBindingElement.AllowCookies value if (http == null) { foreach (BindingElement bindingElement in bindingElements) { http = bindingElement as HttpTransportBindingElement; if (http != null) { break; } } } if (http != null && http.AllowCookies) { http.AllowCookies = false; if (BasicHttpBinding.TryCreate(bindingElements, out binding)) { ((BasicHttpBinding)binding).AllowCookies = true; } } } if (binding != null) { binding.Name = context.Endpoint.Binding.Name; binding.Namespace = context.Endpoint.Binding.Namespace; context.Endpoint.Binding = binding; } } }
public void ImportEndpoint(WsdlImporter importer, WsdlEndpointConversionContext context) { if (context == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("context"); } if (context.Endpoint == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("context.Endpoint"); } if (context.Endpoint.Binding == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("context.Endpoint.Binding"); } CustomBinding binding = context.Endpoint.Binding as CustomBinding; if (binding != null) { System.ServiceModel.Channels.Binding binding2; UnrecognizedAssertionsBindingElement item = null; item = binding.Elements.Find <UnrecognizedAssertionsBindingElement>(); HttpTransportBindingElement element2 = null; if (item != null) { XmlElement httpUseCookieAssertion = null; if (ContextBindingElementPolicy.TryGetHttpUseCookieAssertion(item.BindingAsserions, out httpUseCookieAssertion)) { foreach (BindingElement element4 in binding.Elements) { element2 = element4 as HttpTransportBindingElement; if (element2 != null) { element2.AllowCookies = true; item.BindingAsserions.Remove(httpUseCookieAssertion); if (item.BindingAsserions.Count == 0) { binding.Elements.Remove(item); } break; } } } } BindingElementCollection bindingElements = binding.CreateBindingElements(); if (!WSHttpContextBinding.TryCreate(bindingElements, out binding2) && !NetTcpContextBinding.TryCreate(bindingElements, out binding2)) { if (element2 == null) { foreach (BindingElement element5 in bindingElements) { element2 = element5 as HttpTransportBindingElement; if (element2 != null) { break; } } } if ((element2 != null) && element2.AllowCookies) { element2.AllowCookies = false; if (BasicHttpBinding.TryCreate(bindingElements, out binding2)) { ((BasicHttpBinding)binding2).AllowCookies = true; } } } if (binding2 != null) { binding2.Name = context.Endpoint.Binding.Name; binding2.Namespace = context.Endpoint.Binding.Namespace; context.Endpoint.Binding = binding2; } } }
/// <summary> /// Creates the appropriate binding type for the given element /// </summary> /// <param name="endPoint">Enpoint to create binding object for</param> /// <returns>Binding represented in the config file</returns> private static Binding GetBinding(ChannelEndpointElement endPoint) { Binding binding = null; try { switch (endPoint.Binding) { case "basicHttpBinding": if (!string.IsNullOrEmpty(endPoint.BindingConfiguration)) { binding = new BasicHttpBinding(endPoint.BindingConfiguration); } else { binding = new BasicHttpBinding(); } break; case "basicHttpContextBinding": if (!string.IsNullOrEmpty(endPoint.BindingConfiguration)) { binding = new BasicHttpContextBinding(endPoint.BindingConfiguration); } else { binding = new BasicHttpContextBinding(); } break; case "customBinding": if (!string.IsNullOrEmpty(endPoint.BindingConfiguration)) { binding = new CustomBinding(endPoint.BindingConfiguration); } else { binding = new CustomBinding(); } break; case "netNamedPipeBinding": if (!string.IsNullOrEmpty(endPoint.BindingConfiguration)) { binding = new NetNamedPipeBinding(endPoint.BindingConfiguration); } else { binding = new NetNamedPipeBinding(); } break; case "netPeerTcpBinding": if (!string.IsNullOrEmpty(endPoint.BindingConfiguration)) { binding = new NetPeerTcpBinding(endPoint.BindingConfiguration); } else { binding = new NetPeerTcpBinding(); } break; case "netTcpBinding": if (!string.IsNullOrEmpty(endPoint.BindingConfiguration)) { binding = new NetTcpBinding(endPoint.BindingConfiguration); } else { binding = new NetTcpBinding(); } break; case "netTcpContextBinding": if (!string.IsNullOrEmpty(endPoint.BindingConfiguration)) { binding = new NetTcpContextBinding(endPoint.BindingConfiguration); } else { binding = new NetTcpContextBinding(); } break; case "webHttpBinding": if (!string.IsNullOrEmpty(endPoint.BindingConfiguration)) { binding = new WebHttpBinding(endPoint.BindingConfiguration); } else { binding = new WebHttpBinding(); } break; case "ws2007HttpBinding": if (!string.IsNullOrEmpty(endPoint.BindingConfiguration)) { binding = new WS2007HttpBinding(endPoint.BindingConfiguration); } else { binding = new WS2007HttpBinding(); } break; case "wsHttpBinding": if (!string.IsNullOrEmpty(endPoint.BindingConfiguration)) { binding = new WSHttpBinding(endPoint.BindingConfiguration); } else { binding = new WSHttpBinding(); } break; case "wsHttpContextBinding": if (!string.IsNullOrEmpty(endPoint.BindingConfiguration)) { binding = new WSHttpContextBinding(endPoint.BindingConfiguration); } else { binding = new WSHttpContextBinding(); } break; case "wsDualHttpBinding": if (!string.IsNullOrEmpty(endPoint.BindingConfiguration)) { binding = new WSDualHttpBinding(endPoint.BindingConfiguration); } else { binding = new WSDualHttpBinding(); } break; case "wsFederationHttpBinding": if (!string.IsNullOrEmpty(endPoint.BindingConfiguration)) { binding = new WSFederationHttpBinding(endPoint.BindingConfiguration); } else { binding = new WSFederationHttpBinding(); } break; case "ws2007FederationHttpBinding": if (!string.IsNullOrEmpty(endPoint.BindingConfiguration)) { binding = new WS2007FederationHttpBinding(endPoint.BindingConfiguration); } else { binding = new WS2007FederationHttpBinding(); } break; case "msmqIntegrationBinding": if (!string.IsNullOrEmpty(endPoint.BindingConfiguration)) { binding = new MsmqIntegrationBinding(endPoint.BindingConfiguration); } else { binding = new MsmqIntegrationBinding(); } break; case "netMsmqBinding": if (!string.IsNullOrEmpty(endPoint.BindingConfiguration)) { binding = new NetMsmqBinding(endPoint.BindingConfiguration); } else { binding = new NetMsmqBinding(); } break; case "netHttpBinding": if (!string.IsNullOrEmpty(endPoint.BindingConfiguration)) { binding = new NetHttpBinding(endPoint.BindingConfiguration); } else { binding = new NetHttpBinding(); } break; case "netHttpsBinding": if (!string.IsNullOrEmpty(endPoint.BindingConfiguration)) { binding = new NetHttpsBinding(endPoint.BindingConfiguration); } else { binding = new NetHttpBinding(); } break; } } catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex.Message, System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Namespace + "." + System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + System.Reflection.MethodBase.GetCurrentMethod().Name); throw ex; } return(binding); }