/// <summary> /// Build the net.tcp frontend /// </summary> /// <param name="sharedData">indicating the shared data</param> /// <param name="observer">indicating the broker observer</param> /// <param name="clientManager">indicating the client manager</param> /// <param name="brokerAuth">indicating the broker authorization</param> /// <param name="bindings">indicating the bindings</param> /// <returns>frontend info</returns> private static FrontendInfo BuildNetTcpFrontend(SharedData sharedData, BrokerObserver observer, BrokerClientManager clientManager, BrokerAuthorization brokerAuth, BindingsSection bindings) { FrontendInfo result = new FrontendInfo(); BrokerTracing.TraceVerbose("[FrontEndBuilder] Start building net.tcp frontend..."); // Get binding from configuration file Binding binding = BindingHelper.GetBinding(TransportScheme.NetTcp, sharedData.StartInfo.Secure, bindings, sharedData.StartInfo.LocalUser.GetValueOrDefault(), sharedData.StartInfo.UseAad); // Sync frontend binding.receiveTimeout with loadBalancing.ServiceOperationTimeout if its enabled (>0) int serviceOperationTimeout = sharedData.Config.LoadBalancing.ServiceOperationTimeout; if (serviceOperationTimeout > 0) { binding.SendTimeout = TimeSpan.FromMilliseconds(serviceOperationTimeout); } // Set frontend binding.ReceiveTimeout to max binding.ReceiveTimeout = TimeSpan.MaxValue; // Update backend binding's maxMessageSize settings with global maxMessageSize if its enabled (> 0) int maxMessageSize = sharedData.ServiceConfig.MaxMessageSize; if (maxMessageSize > 0) { BindingHelper.ApplyMaxMessageSize(binding, maxMessageSize); result.MaxMessageSize = maxMessageSize; BrokerTracing.TraceVerbose("[FrontEndBuilder] Build frontend: Step 1: Apply global MaxMessageSize:{0}\n", result.MaxMessageSize); } else { // Get message size and reader quotas BindingElementCollection collection = binding.CreateBindingElements(); result.MaxMessageSize = collection.Find <TransportBindingElement>().MaxReceivedMessageSize; result.ReaderQuotas = binding.GetProperty <XmlDictionaryReaderQuotas>(new BindingParameterCollection()); StringBuilder sb = new StringBuilder(); BrokerTracing.WriteProperties(sb, result.ReaderQuotas, 3, typeof(int)); BrokerTracing.TraceVerbose("[FrontEndBuilder] Build frontend: Step 1: Load binding data:\nMaxMessageSize = {0}\n[ReaderQuotas]\n{1}", result.MaxMessageSize, sb.ToString()); } result.Binding = binding; BrokerTracing.EtwTrace.LogFrontendBindingLoaded( sharedData.BrokerInfo.SessionId, "NetTcp", result.MaxMessageSize, binding.ReceiveTimeout.Ticks, binding.SendTimeout.Ticks, binding.MessageVersion.ToString(), binding.Scheme); // Generate the net.tcp uri Uri baseNetTcpUri = sharedData.Config.Services.GetBrokerBaseAddress(NetTcpScheme); if (baseNetTcpUri == null) { string netTcpUriStr; if (sharedData.StartInfo.LocalUser.GetValueOrDefault()) { netTcpUriStr = InternalNetTcpFrontEndServiceUri; } else if (sharedData.StartInfo.UseAad) { netTcpUriStr = AadNetTcpFrontEndServiceUri; } else { netTcpUriStr = DefaultNetTcpFrontEndServiceUri; } baseNetTcpUri = new Uri(netTcpUriStr); } if (SoaHelper.IsOnAzure()) { baseNetTcpUri = new Uri(SoaHelper.GetBrokerWorkerAddress("localhost")); } BrokerTracing.TraceVerbose("[FrontEndBuilder] Build frontend: Step 2: Load base address: {0}", baseNetTcpUri); Uri brokerNetTcpUri = ApplySessionId(baseNetTcpUri, sharedData.BrokerInfo.SessionId, "NetTcp", sharedData.BrokerInfo.EnableFQDN); BrokerTracing.TraceVerbose("[FrontEndBuilder] Build frontend: Step 3: Generate broker uri: {0}", brokerNetTcpUri); // Build the frontend result.FrontEnd = new DuplexFrontEnd(brokerNetTcpUri, binding, observer, clientManager, brokerAuth, sharedData); BrokerTracing.TraceVerbose("[FrontEndBuilder] Build frontend: Step 4: Build broker frontend succeeded."); BrokerTracing.EtwTrace.LogFrontendCreated( sharedData.BrokerInfo.SessionId, "NetTcp", result.FrontEnd.ListenUri); Uri controllerNetTcpUri = ApplySessionId(baseNetTcpUri, sharedData.BrokerInfo.SessionId, "NetTcp", sharedData.BrokerInfo.EnableFQDN); BrokerTracing.TraceVerbose("[FrontEndBuilder] Build frontend: Step 5: Generate controller base address: {0}", controllerNetTcpUri); if (SoaHelper.IsOnAzure()) { result.ControllerFrontend = new ServiceHost(typeof(BrokerController)); BindingHelper.ApplyDefaultThrottlingBehavior(result.ControllerFrontend); ServiceEndpoint controllerEndpoint = result.ControllerFrontend.AddServiceEndpoint( typeof(IController), binding, new Uri(SoaHelper.GetBrokerControllerAddress(sharedData.BrokerInfo.SessionId)), new Uri(Path.Combine(controllerNetTcpUri.ToString(), DefaultControllerPostfix))); controllerEndpoint.Behaviors.Add(new ControllerFrontendProvider(false, clientManager, brokerAuth, observer, null)); result.ControllerUri = controllerEndpoint.ListenUri.AbsoluteUri; ServiceEndpoint getResponseEndpoint = result.ControllerFrontend.AddServiceEndpoint( typeof(IResponseService), binding, new Uri(SoaHelper.GetBrokerGetResponseAddress(sharedData.BrokerInfo.SessionId)), new Uri(Path.Combine(controllerNetTcpUri.ToString(), DefaultGetResponsePostfix))); getResponseEndpoint.Behaviors.Add(new ControllerFrontendProvider(false, clientManager, brokerAuth, observer, null)); result.GetResponseUri = getResponseEndpoint.ListenUri.AbsoluteUri; } else { result.ControllerFrontend = new ServiceHost(typeof(BrokerController), controllerNetTcpUri); BindingHelper.ApplyDefaultThrottlingBehavior(result.ControllerFrontend); ServiceEndpoint controllerEndpoint = result.ControllerFrontend.AddServiceEndpoint(typeof(IController), binding, DefaultControllerPostfix); controllerEndpoint.Behaviors.Add(new ControllerFrontendProvider(false, clientManager, brokerAuth, observer, null)); result.ControllerUri = controllerEndpoint.ListenUri.AbsoluteUri; ServiceEndpoint getResponseEndpoint = result.ControllerFrontend.AddServiceEndpoint(typeof(IResponseService), binding, DefaultGetResponsePostfix); getResponseEndpoint.Behaviors.Add(new ControllerFrontendProvider(false, clientManager, brokerAuth, observer, null)); result.GetResponseUri = getResponseEndpoint.ListenUri.AbsoluteUri; if (sharedData.StartInfo.UseAad) { throw new NotSupportedException(); } else if (sharedData.StartInfo.LocalUser.GetValueOrDefault()) { BrokerTracing.TraceVerbose("[FrontEndBuilder] Building net.tcp frontend with internal authentication."); result.ControllerFrontend.Credentials.UseInternalAuthenticationAsync(true).GetAwaiter().GetResult(); } } BrokerTracing.TraceVerbose("[FrontEndBuilder] Build frontend: Step 6: Build controller frontend succeeded: ControllerUri = {0}, GetResponseUri = {1}", result.ControllerUri, result.GetResponseUri); BrokerTracing.TraceVerbose("[FrontEndBuilder] Building net.tcp frontend succeeded."); BrokerTracing.EtwTrace.LogFrontendControllerCreated( sharedData.BrokerInfo.SessionId, "NetTcp", result.ControllerUri, result.GetResponseUri); return(result); }