/// <summary> /// Create the channel factory for calling the session manager in the host /// </summary> /// <param name="sessionManagerProcessId"></param> private static void SetSessionManagerProcessId(int sessionManagerProcessId) { string sessionManagerEndpointAddress = Nomenclator.GetIPCEndpointAddress(typeof(INativeSessionManager), sessionManagerProcessId); EndpointAddress endpointAddress = new EndpointAddress(sessionManagerEndpointAddress); NativeSessionManagerClientFactory = new ChannelFactory <INativeSessionManager>("NativeSessionManager_IPCEndpoint", endpointAddress); }
/// <summary> /// Open the service endpoint(s) and wait for connection from client /// For this method to operate properly the following must be setup: /// 1. .Net port sharing must be set up by issueing the following /// command under an admin account: sc.exe config NetTcpPortSharing start= demand /// 2. Must run the app in admin mode or the current user must be added /// to the allowedAccounts section in the SMSvcHost.exe.config file. /// </summary> private static void OpenServiceHost() { int processId = Process.GetCurrentProcess().Id; NativeSessionHost nativeSessionHost = // Create the native session host obj for the IPC and NetTcp service hosts to use new NativeSessionHost(); ServiceHost serviceHost = // Create the host object new ServiceHost(nativeSessionHost); // Add the native session's IPC endpoint (for use by the NativeSessionManager) string endpointAddressName = Nomenclator.GetIPCEndpointAddress(typeof(Types.Internal.INativeSession), processId); NetNamedPipeBinding ipcBinding = new NetNamedPipeBinding("ipcBinding"); ServiceEndpoint ipcEndpoint = serviceHost.AddServiceEndpoint( typeof(Types.Internal.INativeSession), ipcBinding, new Uri(endpointAddressName)); // Add the NetTcp endpoint (for use by the native client) NativeSessionEndpointAddress.ServiceHostName = ServiceHostUtil.HostName; NativeSessionEndpointAddress.ServicePort = ServiceHostUtil.BasePort + 5; // //port offset for native services = +2 endpointAddressName = NativeSessionEndpointAddress.Build(processId); NetTcpBinding tcpBinding = new NetTcpBinding("tcpBinding"); ServiceEndpoint tcpEndpoint = serviceHost.AddServiceEndpoint( typeof(Native.INativeSession), tcpBinding, new Uri(endpointAddressName)); // Up the value of maxItemsInObjectGraph so that the MetaTree can pass over the wire... foreach (OperationDescription op in tcpEndpoint.Contract.Operations) { if (op.Name != "InvokeNativeMethod") { continue; } DataContractSerializerOperationBehavior dataContractBehavior = op.Behaviors.Find <DataContractSerializerOperationBehavior>() as DataContractSerializerOperationBehavior; if (dataContractBehavior != null) { dataContractBehavior.MaxItemsInObjectGraph = 2147483647; } } // We really don't need to do this anymore. Why rewrite the address? Just keep the address from the config file. //ServiceHostUtil.ApplyEndpointAddressAndIdentityConfig(serviceHost); serviceHost.Open(); // Open the host }