public static void SetClientBaseAddress <T>(this DuplexClientBase <T> proxy, int port, string machineIpOrName) where T : class { WSDualHttpBinding binding = proxy.Endpoint.Binding as WSDualHttpBinding; Debug.Assert(binding != null); binding.ClientBaseAddress = new Uri("http://" + machineIpOrName + ":" + port + "/"); }
public static void SetClientBaseAddress <T>(this DuplexClientBase <T> proxy, int port) where T : class { WSDualHttpBinding binding = proxy.Endpoint.Binding as WSDualHttpBinding; Debug.Assert(binding != null); binding.ClientBaseAddress = new Uri("http://localhost:" + port + "/"); }
public static void DuplexClientBaseOfT_OverNetTcp_Synchronous_Call() { DuplexClientBase <IWcfDuplexService> duplexService = null; Guid guid = Guid.NewGuid(); try { NetTcpBinding binding = new NetTcpBinding(); binding.Security.Mode = SecurityMode.None; WcfDuplexServiceCallback callbackService = new WcfDuplexServiceCallback(); InstanceContext context = new InstanceContext(callbackService); duplexService = new MyDuplexClientBase <IWcfDuplexService>(context, binding, new EndpointAddress(Endpoints.Tcp_NoSecurity_Callback_Address)); IWcfDuplexService proxy = duplexService.ChannelFactory.CreateChannel(); // Ping on another thread. Task.Run(() => proxy.Ping(guid)); Guid returnedGuid = callbackService.CallbackGuid; Assert.True(guid == returnedGuid, string.Format("The sent GUID does not match the returned GUID. Sent '{0}', Received: '{1}'", guid, returnedGuid)); ((ICommunicationObject)duplexService).Close(); } finally { if (duplexService != null && duplexService.State != CommunicationState.Closed) { duplexService.Abort(); } } }
public static void IOperationBehavior_Methods_AreCalled() { DuplexClientBase <ICustomOperationBehaviorDuplexService> duplexService = null; ICustomOperationBehaviorDuplexService proxy = null; NetTcpBinding binding = new NetTcpBinding(); binding.Security.Mode = SecurityMode.None; WcfDuplexServiceCallback callbackService = new WcfDuplexServiceCallback(); InstanceContext context = new InstanceContext(callbackService); duplexService = new MyDuplexClientBase <ICustomOperationBehaviorDuplexService>(context, binding, new EndpointAddress(FakeAddress.TcpAddress)); proxy = duplexService.ChannelFactory.CreateChannel(); // Wait to validate until the process has been given a reasonable time to complete. Task[] taskCollection = { MyOperationBehavior.validateMethodTcs.Task, MyOperationBehavior.addBindingParametersMethodTcs.Task, MyOperationBehavior.applyClientBehaviorMethodTcs.Task }; bool waitAll = Task.WaitAll(taskCollection, 250); Assert.True(MyOperationBehavior.errorBuilder.Length == 0, "Test case FAILED with errors: " + MyOperationBehavior.errorBuilder.ToString()); Assert.True(waitAll, "None of the IOperationBehavior methods were called."); ((ICommunicationObject)proxy).Close(); ((ICommunicationObject)duplexService).Close(); }
public static void SetClientBaseAddress <T>(this DuplexClientBase <T> proxy) where T : class { lock (typeof(WsDualProxyHelper)) { int portNumber = FindPort(); SetClientBaseAddress(proxy, portNumber); proxy.Open(); } }
public static void DuplexClientBaseOfT_OverHttp_Call_Throws_InvalidOperation() { #if FULLXUNIT_NOTSUPPORTED bool root_Certificate_Installed = Root_Certificate_Installed(); if (!root_Certificate_Installed) { Console.WriteLine("---- Test SKIPPED --------------"); Console.WriteLine("Attempting to run the test in ToF, a ConditionalFact evaluated as FALSE."); Console.WriteLine("Root_Certificate_Installed evaluated as {0}", root_Certificate_Installed); return; } #endif DuplexClientBase <IWcfDuplexService> duplexService = null; IWcfDuplexService proxy = null; try { // *** SETUP *** \\ BasicHttpBinding binding = new BasicHttpBinding(BasicHttpSecurityMode.None); WcfDuplexServiceCallback callbackService = new WcfDuplexServiceCallback(); InstanceContext context = new InstanceContext(callbackService); duplexService = new MyDuplexClientBase <IWcfDuplexService>(context, binding, new EndpointAddress(Endpoints.Https_DefaultBinding_Address)); // *** EXECUTE *** \\ var exception = Assert.Throws <InvalidOperationException>(() => { proxy = duplexService.ChannelFactory.CreateChannel(); }); // *** VALIDATE *** \\ // Can't compare the entire exception message - .NET Native doesn't necessarily output the entire message, just params // "Contract requires Duplex, but Binding 'BasicHttpBinding' doesn't support it or isn't configured properly to support it" Assert.True(exception.Message.Contains("BasicHttpBinding")); Assert.Throws <CommunicationObjectFaultedException>(() => { // You can't gracefully close a Faulted CommunicationObject, so we should make sure it throws here too ((ICommunicationObject)duplexService).Close(); }); // *** CLEANUP *** \\ // proxy will be null here so can't close. // duplexService is closed prior to this as part of an assert to verify an expected exception. } finally { // *** ENSURE CLEANUP *** \\ ScenarioTestHelpers.CloseCommunicationObjects((ICommunicationObject)proxy, duplexService); } }
public void OnAfterUnsubcribed(DuplexClientBase <T> client) { ModuleProc PROC = new ModuleProc(this.DYN_MODULE_NAME, "OnAfterUnsubcribed"); try { if (this.AfterUnsubcribed != null) { this.AfterUnsubcribed(client); } } catch (Exception ex) { Log.Exception(PROC, ex); } }
public static void DuplexClientBaseOfT_OverNetTcp_Call() { DuplexClientBase <IWcfDuplexService> duplexService = null; StringBuilder errorBuilder = new StringBuilder(); Guid guid = Guid.NewGuid(); try { NetTcpBinding binding = new NetTcpBinding(); binding.Security.Mode = SecurityMode.None; WcfDuplexServiceCallback callbackService = new WcfDuplexServiceCallback(); InstanceContext context = new InstanceContext(callbackService); duplexService = new MyDuplexClientBase <IWcfDuplexService>(context, binding, new EndpointAddress(Endpoints.Tcp_NoSecurity_Callback_Address)); IWcfDuplexService proxy = duplexService.ChannelFactory.CreateChannel(); // Ping on another thread. Task.Run(() => proxy.Ping(guid)); Guid returnedGuid = callbackService.CallbackGuid; if (guid != returnedGuid) { errorBuilder.AppendLine(String.Format("The sent GUID does not match the returned GUID. Sent: {0} Received: {1}", guid, returnedGuid)); } ((ICommunicationObject)duplexService).Close(); } catch (Exception ex) { errorBuilder.AppendLine(String.Format("Unexpected exception was caught: {0}", ex.ToString())); for (Exception innerException = ex.InnerException; innerException != null; innerException = innerException.InnerException) { errorBuilder.AppendLine(String.Format("Inner exception: {0}", innerException.ToString())); } } finally { if (duplexService != null && duplexService.State != CommunicationState.Closed) { duplexService.Abort(); } } Assert.True(errorBuilder.Length == 0, string.Format("Test Scenario: DuplexClientBaseOfT_OverNetTcp_Call FAILED with the following errors: {0}", errorBuilder)); }
public static void DuplexClientBaseOfT_OverHttp_Call_Throws_InvalidOperation() { DuplexClientBase <IWcfDuplexService> duplexService = null; IWcfDuplexService proxy = null; try { // *** SETUP *** \\ BasicHttpBinding binding = new BasicHttpBinding(BasicHttpSecurityMode.None); WcfDuplexServiceCallback callbackService = new WcfDuplexServiceCallback(); InstanceContext context = new InstanceContext(callbackService); duplexService = new MyDuplexClientBase <IWcfDuplexService>(context, binding, new EndpointAddress(Endpoints.Https_DefaultBinding_Address)); // *** EXECUTE *** \\ var exception = Assert.Throws <InvalidOperationException>(() => { proxy = duplexService.ChannelFactory.CreateChannel(); }); // *** VALIDATE *** \\ // Can't compare the entire exception message - .NET Native doesn't necessarily output the entire message, just params // "Contract requires Duplex, but Binding 'BasicHttpBinding' doesn't support it or isn't configured properly to support it" Assert.Contains("BasicHttpBinding", exception.Message); Assert.Throws <CommunicationObjectFaultedException>(() => { // You can't gracefully close a Faulted CommunicationObject, so we should make sure it throws here too ((ICommunicationObject)duplexService).Close(); }); // *** CLEANUP *** \\ // proxy will be null here so can't close. // duplexService is closed prior to this as part of an assert to verify an expected exception. } finally { // *** ENSURE CLEANUP *** \\ ScenarioTestHelpers.CloseCommunicationObjects((ICommunicationObject)proxy, duplexService); } }
public void Unsubscribe(ref DuplexClientBase <T> client) { ModuleProc PROC = new ModuleProc(this.DYN_MODULE_NAME, "Unsubscribe"); try { if (client != null) { this.Unsubscribe(client); this.AfterUnsubcribed(client); } } catch (Exception ex) { if (!this.SkipLogException) { Log.Exception(PROC, ex); } } }
/// <summary> /// Transitions proxy to closed state via Close() or Abort() /// dependently on current proxy state /// </summary> public static void CloseProxy <T>(this DuplexClientBase <T> proxy) where T : class { try { if (proxy.State != CommunicationState.Closed && proxy.State != CommunicationState.Faulted) { proxy.Close(); // may throw exception while closing } else { proxy.Abort(); } } catch (CommunicationException) { proxy.Abort(); throw; } }
public void Subscribe(ref DuplexClientBase <T> client) { ModuleProc PROC = new ModuleProc(this.DYN_MODULE_NAME, "Subscribe"); try { if (client != null) { this.Subscribe(client); if (client.State == CommunicationState.Opened) { this.AfterSubcribed(client); } } } catch (Exception ex) { if (!this.SkipLogException) { Log.Exception(PROC, ex); } } }
public static void DuplexClientBaseOfT_OverHttp_Call_Throws_InvalidOperation() { DuplexClientBase <IWcfDuplexService> duplexService = null; Guid guid = Guid.NewGuid(); try { BasicHttpBinding binding = new BasicHttpBinding(BasicHttpSecurityMode.None); WcfDuplexServiceCallback callbackService = new WcfDuplexServiceCallback(); InstanceContext context = new InstanceContext(callbackService); duplexService = new MyDuplexClientBase <IWcfDuplexService>(context, binding, new EndpointAddress(Endpoints.Https_DefaultBinding_Address)); var exception = Assert.Throws <InvalidOperationException>(() => { IWcfDuplexService proxy = duplexService.ChannelFactory.CreateChannel(); }); // Can't compare the entire exception message - .NET Native doesn't necessarily output the entire message, just params // "Contract requires Duplex, but Binding 'BasicHttpBinding' doesn't support it or isn't configured properly to support it" Assert.True(exception.Message.Contains("BasicHttpBinding")); Assert.Throws <CommunicationObjectFaultedException>(() => { // You can't gracefully close a Faulted CommunicationObject, so we should make sure it throws here too ((ICommunicationObject)duplexService).Close(); }); } finally { if (duplexService != null && duplexService.State != CommunicationState.Closed) { duplexService.Abort(); } } }
public static void DuplexClientBaseOfT_OverNetTcp_Synchronous_Call() { DuplexClientBase <IWcfDuplexService> duplexService = null; IWcfDuplexService proxy = null; Guid guid = Guid.NewGuid(); try { // *** SETUP *** \\ NetTcpBinding binding = new NetTcpBinding(); binding.Security.Mode = SecurityMode.None; WcfDuplexServiceCallback callbackService = new WcfDuplexServiceCallback(); InstanceContext context = new InstanceContext(callbackService); duplexService = new MyDuplexClientBase <IWcfDuplexService>(context, binding, new EndpointAddress(Endpoints.Tcp_NoSecurity_Callback_Address)); proxy = duplexService.ChannelFactory.CreateChannel(); // *** EXECUTE *** \\ // Ping on another thread. Task.Run(() => proxy.Ping(guid)); Guid returnedGuid = callbackService.CallbackGuid; // *** VALIDATE *** \\ Assert.True(guid == returnedGuid, string.Format("The sent GUID does not match the returned GUID. Sent '{0}', Received: '{1}'", guid, returnedGuid)); // *** CLEANUP *** \\ ((ICommunicationObject)duplexService).Close(); ((ICommunicationObject)proxy).Close(); } finally { // *** ENSURE CLEANUP *** \\ ScenarioTestHelpers.CloseCommunicationObjects((ICommunicationObject)proxy, (ICommunicationObject)duplexService); } }
public PubSubClientChannel(DuplexClientBase <IPubSub> client) : base(client) { }
public static void SetClientBaseAddress <T>(this DuplexClientBase <T> proxy) where T : class { SetClientBaseAddress(proxy, "localhost"); }
private DuplexClientBase <T> InitiateClient(ref DuplexClientBase <T> client, bool skipSubscribe) { ModuleProc PROC = new ModuleProc(this.DYN_MODULE_NAME, "InitiateClient"); try { if (client == null || (client.State != System.ServiceModel.CommunicationState.Opened)) { if (this.ExecutorService.IsShutdown) { return(null); } if (client != null) { if (!skipSubscribe) { this.Unsubscribe(ref client); } try { if (client.State == CommunicationState.Opened) { client.Close(); } } catch { } client = null; } try { client = this.CreateClient(); } catch (Exception ex) { if (!this.SkipLogException) { Log.Exception(PROC, ex); } client = null; } if (client != null) { if (client is IWcfCallbackServiceClient) { ((IWcfCallbackServiceClient)client).SkipLogException = _skipLogException; } if (!skipSubscribe) { this.Subscribe(ref client); } } } } catch (Exception ex) { if (!this.SkipLogException) { Log.Exception(PROC, ex); } client = null; } return(client); }
protected abstract void Unsubscribe(DuplexClientBase <T> client);