[ActiveIssue(832)] // Windows Stream Security is not supported in NET Native #endif public static void NetTcp_TransportSecurity_StreamedResponse_Async_RoundTrips_String() { string testString = "Hello"; StringBuilder errorBuilder = new StringBuilder(); NetTcpBinding binding = null; ChannelFactory <IWcfService> factory = null; IWcfService serviceProxy = null; Stream stream = null; try { // *** SETUP *** \\ binding = new NetTcpBinding(SecurityMode.Transport); binding.TransferMode = TransferMode.StreamedResponse; factory = new ChannelFactory <IWcfService>(binding, new EndpointAddress(Endpoints.Tcp_Transport_Security_Streamed_Address)); serviceProxy = factory.CreateChannel(); stream = StringToStream(testString); // *** EXECUTE *** \\ var returnStream = serviceProxy.EchoStreamAsync(stream).Result; var result = StreamToString(returnStream); // *** VALIDATE *** \\ Assert.Equal(testString, result); // *** CLEANUP *** \\ ((ICommunicationObject)serviceProxy).Close(); factory.Close(); } finally { // *** ENSURE CLEANUP *** \\ ScenarioTestHelpers.CloseCommunicationObjects((ICommunicationObject)serviceProxy, factory); } }
public static void BasicHttp_DefaultSettings_Echo_RoundTrips_String_Streamed_Async() { string testString = "Hello"; BasicHttpBinding binding = null; ChannelFactory <IWcfService> factory = null; IWcfService serviceProxy = null; Stream stream = null; try { // *** SETUP *** \\ binding = new BasicHttpBinding(BasicHttpSecurityMode.None); binding.TransferMode = TransferMode.Streamed; factory = new ChannelFactory <IWcfService>(binding, new EndpointAddress(Endpoints.HttpBaseAddress_Basic_Text)); serviceProxy = factory.CreateChannel(); stream = StringToStream(testString); // *** EXECUTE *** \\ var returnStream = serviceProxy.EchoStreamAsync(stream).Result; var result = StreamToString(returnStream); // *** VALIDATE *** \\ Assert.Equal(testString, result); // *** CLEANUP *** \\ ((ICommunicationObject)serviceProxy).Close(); factory.Close(); } finally { // *** ENSURE CLEANUP *** \\ ScenarioTestHelpers.CloseCommunicationObjects((ICommunicationObject)serviceProxy, factory); } }
public static void DefaultSettings_Echo_RoundTrips_String_Streamed_Async() { string testString = "Hello"; StringBuilder errorBuilder = new StringBuilder(); BasicHttpBinding binding = new BasicHttpBinding(BasicHttpSecurityMode.None); binding.TransferMode = TransferMode.Streamed; ChannelFactory <IWcfService> factory = new ChannelFactory <IWcfService>(binding, new EndpointAddress(Endpoints.HttpBaseAddress_Basic)); IWcfService serviceProxy = factory.CreateChannel(); try { Stream stream = StringToStream(testString); var returnStream = serviceProxy.EchoStreamAsync(stream).Result; var result = StreamToString(returnStream); Assert.Equal(testString, result); } catch (System.ServiceModel.CommunicationException e) { errorBuilder.AppendLine(string.Format("Unexpected exception thrown: '{0}'", e.ToString())); PrintInnerExceptionsHresult(e, errorBuilder); } finally { if (factory != null && factory.State != CommunicationState.Closed) { factory.Abort(); } } Assert.True(errorBuilder.Length == 0, string.Format("Test Scenario: DefaultSettings_Echo_RoundTrips_String_Streamed FAILED with the following errors: {0}", errorBuilder)); }
public static void NetTcp_TransportSecurity_StreamedResponse_Async_RoundTrips_String() { #if FULLXUNIT_NOTSUPPORTED bool root_Certificate_Installed = Root_Certificate_Installed(); bool client_Certificate_Installed = Client_Certificate_Installed(); bool windows_Authentication_Available = Windows_Authentication_Available(); bool ambient_Credentials_Available = Ambient_Credentials_Available(); if (!root_Certificate_Installed || !client_Certificate_Installed || !windows_Authentication_Available || !ambient_Credentials_Available) { 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); Console.WriteLine("Client_Certificate_Installed evaluated as {0}", client_Certificate_Installed); Console.WriteLine("Windows_Authentication_Available evaluated as {0}", windows_Authentication_Available); Console.WriteLine("Ambient_Credentials_Available evaluated as {0}", ambient_Credentials_Available); return; } #endif string testString = "Hello"; StringBuilder errorBuilder = new StringBuilder(); NetTcpBinding binding = null; ChannelFactory <IWcfService> factory = null; IWcfService serviceProxy = null; Stream stream = null; try { // *** SETUP *** \\ binding = new NetTcpBinding(SecurityMode.Transport); binding.TransferMode = TransferMode.StreamedResponse; factory = new ChannelFactory <IWcfService>(binding, new EndpointAddress(Endpoints.Tcp_Transport_Security_Streamed_Address)); serviceProxy = factory.CreateChannel(); stream = StringToStream(testString); // *** EXECUTE *** \\ var returnStream = serviceProxy.EchoStreamAsync(stream).Result; var result = StreamToString(returnStream); // *** VALIDATE *** \\ Assert.Equal(testString, result); // *** CLEANUP *** \\ ((ICommunicationObject)serviceProxy).Close(); factory.Close(); } finally { // *** ENSURE CLEANUP *** \\ ScenarioTestHelpers.CloseCommunicationObjects((ICommunicationObject)serviceProxy, factory); } }
public static void BasicHttp_Streamed_Async_Delayed_Request_Throws_TimeoutException() { BasicHttpBinding binding = null; ChannelFactory <IWcfService> factory = null; IWcfService serviceProxy = null; Stream stream = null; int sendTimeoutMs = 3000; try { // *** SETUP *** \\ binding = new BasicHttpBinding(BasicHttpSecurityMode.None); binding.TransferMode = TransferMode.Streamed; binding.SendTimeout = TimeSpan.FromMilliseconds(sendTimeoutMs); factory = new ChannelFactory <IWcfService>(binding, new EndpointAddress(Endpoints.HttpBaseAddress_Basic)); serviceProxy = factory.CreateChannel(); // Create a read stream that deliberately times out during the async read during the request. // We also intercept the synchronous read because that path can also be executed during // an async read. stream = new TestMockStream() { CopyToAsyncFunc = (Stream destination, int bufferSize, CancellationToken ct) => { Task.Delay(sendTimeoutMs * 2).Wait(); return(null); }, ReadFunc = (byte[] buffer, int offset, int count) => { Task.Delay(sendTimeoutMs * 2).Wait(); return(-1); } }; // *** EXECUTE *** \\ Assert.Throws <TimeoutException>(() => { var unused = serviceProxy.EchoStreamAsync(stream).GetAwaiter().GetResult(); }); // *** VALIDATE *** \\ // *** CLEANUP *** \\ ((ICommunicationObject)serviceProxy).Close(); factory.Close(); } finally { // *** ENSURE CLEANUP *** \\ ScenarioTestHelpers.CloseCommunicationObjects((ICommunicationObject)serviceProxy, factory); } }
public static void BasicHttp_Streamed_Async_Delayed_And_Aborted_Request_Throws_TimeoutException() { // This test is a regression test that verifies an issue discovered where exceeding the timeout // and aborting the channel before the client's Task completed led to incorrect error handling. BasicHttpBinding binding = null; ChannelFactory <IWcfService> factory = null; IWcfService serviceProxy = null; Stream stream = null; int sendTimeoutMs = 3000; try { // *** SETUP *** \\ binding = new BasicHttpBinding(BasicHttpSecurityMode.None); binding.TransferMode = TransferMode.Streamed; binding.SendTimeout = TimeSpan.FromMilliseconds(sendTimeoutMs); factory = new ChannelFactory <IWcfService>(binding, new EndpointAddress(Endpoints.HttpBaseAddress_Basic)); serviceProxy = factory.CreateChannel(); // Create a read stream that will both timeout and then abort the proxy channel when the // async read is called. We also intercept the synchronous read because that path can also // be executed during an async read. stream = new TestMockStream() { CopyToAsyncFunc = (Stream destination, int bufferSize, CancellationToken ct) => { // Abort to force the internal HttpClientChannelAsyncRequest.Cleanup() // to clear its data structures before the client's Task completes. Task.Delay(sendTimeoutMs * 2).Wait(); ((ICommunicationObject)serviceProxy).Abort(); return(null); }, ReadFunc = (byte[] buffer, int offset, int count) => { // Abort to force the internal HttpClientChannelAsyncRequest.Cleanup() // to clear its data structures before the client's Task completes. Task.Delay(sendTimeoutMs * 2).Wait(); ((ICommunicationObject)serviceProxy).Abort(); return(-1); } }; // *** EXECUTE *** \\ Assert.Throws <TimeoutException>(() => { var unused = serviceProxy.EchoStreamAsync(stream).GetAwaiter().GetResult(); }); // *** VALIDATE *** \\ // *** CLEANUP *** \\ ((ICommunicationObject)serviceProxy).Close(); factory.Close(); } finally { // *** ENSURE CLEANUP *** \\ ScenarioTestHelpers.CloseCommunicationObjects((ICommunicationObject)serviceProxy, factory); } }