public static void ServiceContract_TypedProxy_AsyncTask_CallbackReturn() { DuplexChannelFactory <IWcfDuplexTaskReturnService> factory = null; Guid guid = Guid.NewGuid(); NetTcpBinding binding = new NetTcpBinding(); binding.Security.Mode = SecurityMode.None; DuplexTaskReturnServiceCallback callbackService = new DuplexTaskReturnServiceCallback(); InstanceContext context = new InstanceContext(callbackService); try { factory = new DuplexChannelFactory <IWcfDuplexTaskReturnService>(context, binding, new EndpointAddress(Endpoints.Tcp_NoSecurity_TaskReturn_Address)); IWcfDuplexTaskReturnService serviceProxy = factory.CreateChannel(); Task <Guid> task = serviceProxy.Ping(guid); Guid returnedGuid = task.Result; Assert.Equal(guid, returnedGuid); factory.Close(); } finally { if (factory != null && factory.State != CommunicationState.Closed) { factory.Abort(); } } }
public static void DuplexCallback_Throws_FaultException_ReturnsFaultedTask() { DuplexChannelFactory <IWcfDuplexTaskReturnService> factory = null; Guid guid = Guid.NewGuid(); NetTcpBinding binding = null; DuplexTaskReturnServiceCallback callbackService = null; InstanceContext context = null; EndpointAddress endpointAddress = null; IWcfDuplexTaskReturnService serviceProxy = null; // *** VALIDATE *** \\ FaultException <FaultDetail> exception = Assert.Throws <FaultException <FaultDetail> >(() => { // *** SETUP *** \\ binding = new NetTcpBinding(); binding.Security.Mode = SecurityMode.None; endpointAddress = new EndpointAddress(Endpoints.Tcp_NoSecurity_TaskReturn_Address); callbackService = new DuplexTaskReturnServiceCallback(); context = new InstanceContext(callbackService); factory = new DuplexChannelFactory <IWcfDuplexTaskReturnService>(context, binding, endpointAddress); serviceProxy = factory.CreateChannel(); // *** EXECUTE *** \\ try { Task <Guid> task = serviceProxy.FaultPing(guid); if ((task as IAsyncResult).AsyncWaitHandle.WaitOne(ScenarioTestHelpers.TestTimeout)) { Guid returnedGuid = task.GetAwaiter().GetResult(); } else { throw new TimeoutException(String.Format("The call to the Service did not complete within the alloted time of: {0}", ScenarioTestHelpers.TestTimeout)); } } finally { // *** ENSURE CLEANUP *** \\ ScenarioTestHelpers.CloseCommunicationObjects((ICommunicationObject)serviceProxy, factory); } }); // *** ADDITIONAL VALIDATION *** \\ string exceptionCodeName = "ServicePingFaultCallback"; string exceptionReason = "Reason: Testing FaultException returned from Duplex Callback"; Assert.True(String.Equals(exceptionCodeName, exception.Code.Name), String.Format("Expected exception code name: {0}\nActual exception code name: {1}", exceptionCodeName, exception.Code.Name)); Assert.True(String.Equals(exceptionReason, exception.Reason.GetMatchingTranslation().Text), String.Format("Expected exception reason: {0}\nActual exception reason: {1}", exceptionReason, exception.Reason.GetMatchingTranslation().Text)); }
public static void DuplexCallback_Throws_FaultException_ReturnsFaultedTask() { DuplexChannelFactory <IWcfDuplexTaskReturnService> factory = null; Guid guid = Guid.NewGuid(); NetTcpBinding binding = new NetTcpBinding(); binding.Security.Mode = SecurityMode.None; DuplexTaskReturnServiceCallback callbackService = new DuplexTaskReturnServiceCallback(); InstanceContext context = new InstanceContext(callbackService); try { var exception = Assert.Throws <FaultException <FaultDetail> >(() => { factory = new DuplexChannelFactory <IWcfDuplexTaskReturnService>(context, binding, new EndpointAddress(Endpoints.Tcp_NoSecurity_TaskReturn_Address)); IWcfDuplexTaskReturnService serviceProxy = factory.CreateChannel(); Task <Guid> task = serviceProxy.FaultPing(guid); if ((task as IAsyncResult).AsyncWaitHandle.WaitOne(ScenarioTestHelpers.TestTimeout)) { Guid returnedGuid = task.GetAwaiter().GetResult(); } else { throw new TimeoutException(String.Format("The call to the Service did not complete within the alloted time of: {0}", ScenarioTestHelpers.TestTimeout)); } // Not closing the factory as an exception will always be thrown prior to this point. }); Assert.Equal("ServicePingFaultCallback", exception.Code.Name); Assert.Equal("Reason: Testing FaultException returned from Duplex Callback", exception.Reason.GetMatchingTranslation().Text); } finally { if (factory != null && factory.State != CommunicationState.Closed) { factory.Abort(); } } }