public void Register() { try { foreach (IApiIpcService apiIpcService in apiServices) { Type interfaceType = GetInterfaceType(apiIpcService); string serverName = GetCurrentInstanceServerName(modelMetadataService.ModelFilePath); apiIpcServer?.Dispose(); apiIpcServer = new ApiIpcServer(serverName); if (!apiIpcServer.TryPublishService(interfaceType, apiIpcService)) { throw new ApplicationException($"Failed to register rpc instance {serverName}"); } Log.Info($"Registered: {serverName}"); } } catch (Exception e) { Log.Exception(e); throw; } }
public void Test2() { TestApiService instanceService = new TestApiService(); string serverName = Guid.NewGuid().ToString(); using (ApiIpcServer apiIpcServer = new ApiIpcServer(serverName)) using (ApiIpcClient apiIpcClient = new ApiIpcClient(serverName)) { if (apiIpcServer.TryPublishService <ITestApiService>(instanceService)) { if (ApiIpcClient.IsServerRegistered(serverName)) { // Another instance for that working folder is already running, activate that. ITestApiService service = apiIpcClient.Service <ITestApiService>(); string doubleName = service.GetDoubleName("hej"); Assert.AreEqual("hejhej", doubleName); return; } } } Assert.Fail("Error"); }