private void dataContextChanged(object sender, DependencyPropertyChangedEventArgs e) { this.modelManager = ((ModelManager)this.DataContext); }
private ServiceHost StartNetTcpAndHttpService(ModelManager modelManager, Boolean onlyNetTcp) { Uri[] baseAddresses; if (onlyNetTcp) { baseAddresses = new Uri[] { new Uri($"net.tcp://localhost:{FiskmoMTEngineSettings.Default.MtServicePort}/") }; } else { baseAddresses = new Uri[] { new Uri($"net.tcp://localhost:{FiskmoMTEngineSettings.Default.MtServicePort}/"), new Uri($"http://localhost:8500/") }; }; var mtService = new MTService(modelManager); Log.Information($"Creating service host with following URIs: {String.Join(",",baseAddresses.Select(x => x.ToString()))}"); var selfHost = new ServiceHost(mtService, baseAddresses); // Check to see if the service host already has a ServiceMetadataBehavior ServiceMetadataBehavior smb = selfHost.Description.Behaviors.Find <ServiceMetadataBehavior>(); // If not, add one if (smb == null) { smb = new ServiceMetadataBehavior(); } smb.MetadataExporter.PolicyVersion = PolicyVersion.Policy15; selfHost.Description.Behaviors.Add(smb); // Add MEX endpoint selfHost.AddServiceEndpoint( ServiceMetadataBehavior.MexContractName, MetadataExchangeBindings.CreateMexTcpBinding(), "mex" ); var nettcpBinding = new NetTcpBinding(); //Use default net.tcp security, which is based on Windows authentication: //using the service is only possible from other computers in the same domain. //TODO: add a checkbox (with warning) in the UI for using security mode None, //to allow connections from IP range (also add same checkbox to clients). //nettcpBinding.Security.Mode = SecurityMode.None; /*nettcpBinding.Security.Mode = SecurityMode.Transport; * nettcpBinding.Security.Transport.ClientCredentialType = * TcpClientCredentialType.Windows;*/ //Customization tuning sets tend to be big nettcpBinding.MaxReceivedMessageSize = 20000000; selfHost.AddServiceEndpoint(typeof(IMTService), nettcpBinding, "MTService"); if (!onlyNetTcp) { selfHost.AddServiceEndpoint(typeof(IMTService), new WebHttpBinding(), "MTRestService"); WebHttpBehavior helpBehavior = new WebHttpBehavior(); helpBehavior.HelpEnabled = true; selfHost.Description.Endpoints[2].Behaviors.Add(helpBehavior); } Log.Information($"Opening the service host"); selfHost.Open(); return(selfHost); }