public static void WebSocket_Http_RequestReply_BinaryStreamed() { NetHttpBinding binding = null; ChannelFactory<IWSRequestReplyService> channelFactory = null; IWSRequestReplyService client = null; FlowControlledStream uploadStream = null; try { // *** SETUP *** \\ binding = new NetHttpBinding() { MaxReceivedMessageSize = ScenarioTestHelpers.SixtyFourMB, MaxBufferSize = ScenarioTestHelpers.SixtyFourMB, }; binding.WebSocketSettings.TransportUsage = WebSocketTransportUsage.Always; binding.TransferMode = TransferMode.Streamed; binding.MessageEncoding = NetHttpMessageEncoding.Binary; channelFactory = new ChannelFactory<IWSRequestReplyService>(binding, new EndpointAddress(Endpoints.WebSocketHttpRequestReplyBinaryStreamed_Address)); client = channelFactory.CreateChannel(); // *** EXECUTE *** \\ using (Stream stream = client.DownloadStream()) { int readResult; // Read from the stream, 1000 bytes at a time. byte[] buffer = new byte[1000]; do { readResult = stream.Read(buffer, 0, buffer.Length); } while (readResult != 0); } uploadStream = new FlowControlledStream(); uploadStream.ReadThrottle = TimeSpan.FromMilliseconds(500); uploadStream.StreamDuration = TimeSpan.FromSeconds(1); client.UploadStream(uploadStream); // *** VALIDATE *** \\ foreach (string serverLogItem in client.GetLog()) { //Assert.True(serverLogItem != ScenarioTestHelpers.RemoteEndpointMessagePropertyFailure, ScenarioTestHelpers.RemoteEndpointMessagePropertyFailure); Assert.True(!ScenarioTestHelpers.IsLocalHost() || !serverLogItem.Contains(ScenarioTestHelpers.RemoteEndpointMessagePropertyFailure), serverLogItem); } // *** CLEANUP *** \\ ((ICommunicationObject)client).Close(); channelFactory.Close(); } finally { // *** ENSURE CLEANUP *** \\ ScenarioTestHelpers.CloseCommunicationObjects((ICommunicationObject)client, channelFactory); } }
public static void WebSocket_Http_RequestReply_Streamed(NetHttpMessageEncoding messageEncoding) { EndpointAddress endpointAddress; NetHttpBinding binding = null; ChannelFactory <IWSRequestReplyService> channelFactory = null; IWSRequestReplyService client = null; FlowControlledStream uploadStream = null; try { // *** SETUP *** \\ binding = new NetHttpBinding() { MaxReceivedMessageSize = ScenarioTestHelpers.SixtyFourMB, MaxBufferSize = ScenarioTestHelpers.SixtyFourMB, }; binding.WebSocketSettings.TransportUsage = WebSocketTransportUsage.Always; binding.TransferMode = TransferMode.Streamed; binding.MessageEncoding = messageEncoding; endpointAddress = new EndpointAddress(Endpoints.WebSocketHttpRequestReplyStreamed_Address + Enum.GetName(typeof(NetHttpMessageEncoding), messageEncoding)); channelFactory = new ChannelFactory <IWSRequestReplyService>(binding, endpointAddress); client = channelFactory.CreateChannel(); // *** EXECUTE *** \\ using (Stream stream = client.DownloadStream()) { int readResult; // Read from the stream, 1000 bytes at a time. byte[] buffer = new byte[1000]; do { readResult = stream.Read(buffer, 0, buffer.Length); }while (readResult != 0); } uploadStream = new FlowControlledStream(); uploadStream.ReadThrottle = TimeSpan.FromMilliseconds(500); uploadStream.StreamDuration = TimeSpan.FromSeconds(1); client.UploadStream(uploadStream); // *** VALIDATE *** \\ foreach (string serverLogItem in client.GetLog()) { //Assert.True(serverLogItem != ScenarioTestHelpers.RemoteEndpointMessagePropertyFailure, ScenarioTestHelpers.RemoteEndpointMessagePropertyFailure); Assert.True(!ScenarioTestHelpers.IsLocalHost() || !serverLogItem.Contains(ScenarioTestHelpers.RemoteEndpointMessagePropertyFailure), serverLogItem); } // *** CLEANUP *** \\ ((ICommunicationObject)client).Close(); channelFactory.Close(); } finally { // *** ENSURE CLEANUP *** \\ ScenarioTestHelpers.CloseCommunicationObjects((ICommunicationObject)client, channelFactory); } }
public Stream DownloadCustomizedStream(TimeSpan readThrottle, TimeSpan streamDuration) { log.Add("DownloadStream"); localStream = new FlowControlledStream(); localStream.ReadThrottle = readThrottle; localStream.StreamDuration = streamDuration; return(localStream); }
public Stream DownloadStream() { log.Add("DownloadStream"); localStream = new FlowControlledStream(); localStream.ReadThrottle = TimeSpan.FromMilliseconds(500); // Setting to 900ms instead of 1 second because sometimes 3 reads occur and the read buffer grows with // each read by a factor of 16 up to 64KB and this is causing the client to exceed it's MaxReceivedMessageSize localStream.StreamDuration = TimeSpan.FromMilliseconds(900); return(localStream); }
public static void WebSocket_Http_Duplex_BinaryStreamed() { NetHttpBinding binding = null; ClientReceiver clientReceiver = null; InstanceContext context = null; DuplexChannelFactory <IWSDuplexService> channelFactory = null; IWSDuplexService client = null; FlowControlledStream uploadStream = null; try { // *** SETUP *** \\ binding = new NetHttpBinding() { MaxReceivedMessageSize = ScenarioTestHelpers.SixtyFourMB, MaxBufferSize = ScenarioTestHelpers.SixtyFourMB, }; binding.WebSocketSettings.TransportUsage = WebSocketTransportUsage.Always; binding.TransferMode = TransferMode.Streamed; binding.MessageEncoding = NetHttpMessageEncoding.Binary; clientReceiver = new ClientReceiver(); context = new InstanceContext(clientReceiver); channelFactory = new DuplexChannelFactory <IWSDuplexService>(context, binding, Endpoints.WebSocketHttpDuplexBinaryStreamed_Address); client = channelFactory.CreateChannel(); // *** EXECUTE *** \\ using (Stream stream = client.DownloadStream()) { int readResult; // Read from the stream, 1000 bytes at a time. byte[] buffer = new byte[1000]; do { readResult = stream.Read(buffer, 0, buffer.Length); }while (readResult != 0); } uploadStream = new FlowControlledStream(); uploadStream.ReadThrottle = TimeSpan.FromMilliseconds(500); uploadStream.StreamDuration = TimeSpan.FromSeconds(1); client.UploadStream(uploadStream); client.StartPushingStream(); // Wait for the callback to get invoked before telling the service to stop streaming. // This ensures we can read from the stream on the callback while the NCL layer at the service // is still writing the bytes from the stream to the wire. // This will deadlock if the transfer mode is buffered because the callback will wait for the // stream, and the NCL layer will continue to buffer the stream until it reaches the end. Assert.True(clientReceiver.ReceiveStreamInvoked.WaitOne(ScenarioTestHelpers.TestTimeout), String.Format("Test case timeout was reached while waiting for the stream response from the Service. Timeout was: {0}", ScenarioTestHelpers.TestTimeout)); clientReceiver.ReceiveStreamInvoked.Reset(); // Upload the stream while we are downloading a different stream uploadStream = new FlowControlledStream(); uploadStream.ReadThrottle = TimeSpan.FromMilliseconds(500); uploadStream.StreamDuration = TimeSpan.FromSeconds(1); client.UploadStream(uploadStream); client.StopPushingStream(); // Waiting on ReceiveStreamCompleted from the ClientReceiver. Assert.True(clientReceiver.ReceiveStreamCompleted.WaitOne(ScenarioTestHelpers.TestTimeout), String.Format("Test case timeout was reached while waiting for the stream response from the Service to be completed. Timeout was: {0}", ScenarioTestHelpers.TestTimeout)); clientReceiver.ReceiveStreamCompleted.Reset(); // Getting results from server via callback. client.GetLog(); Assert.True(clientReceiver.LogReceived.WaitOne(ScenarioTestHelpers.TestTimeout), String.Format("Test case timeout was reached while waiting for the Logging from the Service to be received. Timeout was: {0}", ScenarioTestHelpers.TestTimeout)); // *** VALIDATE *** \\ Assert.True(clientReceiver.ServerLog.Count > 0, "The logging done by the Server was not returned via the Callback."); // *** CLEANUP *** \\ ((ICommunicationObject)client).Close(); channelFactory.Close(); } finally { // *** ENSURE CLEANUP *** \\ ScenarioTestHelpers.CloseCommunicationObjects((ICommunicationObject)client, channelFactory); clientReceiver.Dispose(); } }
public static void WebSocket_Http_Duplex_BinaryStreamed() { NetHttpBinding binding = null; ClientReceiver clientReceiver = null; InstanceContext context = null; DuplexChannelFactory<IWSDuplexService> channelFactory = null; IWSDuplexService client = null; FlowControlledStream uploadStream = null; try { // *** SETUP *** \\ binding = new NetHttpBinding() { MaxReceivedMessageSize = ScenarioTestHelpers.SixtyFourMB, MaxBufferSize = ScenarioTestHelpers.SixtyFourMB, }; binding.WebSocketSettings.TransportUsage = WebSocketTransportUsage.Always; binding.TransferMode = TransferMode.Streamed; binding.MessageEncoding = NetHttpMessageEncoding.Binary; clientReceiver = new ClientReceiver(); context = new InstanceContext(clientReceiver); channelFactory = new DuplexChannelFactory<IWSDuplexService>(context, binding, Endpoints.WebSocketHttpDuplexBinaryStreamed_Address); client = channelFactory.CreateChannel(); // *** EXECUTE *** \\ using (Stream stream = client.DownloadStream()) { int readResult; // Read from the stream, 1000 bytes at a time. byte[] buffer = new byte[1000]; do { readResult = stream.Read(buffer, 0, buffer.Length); } while (readResult != 0); } uploadStream = new FlowControlledStream(); uploadStream.ReadThrottle = TimeSpan.FromMilliseconds(500); uploadStream.StreamDuration = TimeSpan.FromSeconds(1); client.UploadStream(uploadStream); client.StartPushingStream(); // Wait for the callback to get invoked before telling the service to stop streaming. // This ensures we can read from the stream on the callback while the NCL layer at the service // is still writing the bytes from the stream to the wire. // This will deadlock if the transfer mode is buffered because the callback will wait for the // stream, and the NCL layer will continue to buffer the stream until it reaches the end. Assert.True(clientReceiver.ReceiveStreamInvoked.WaitOne(ScenarioTestHelpers.TestTimeout), String.Format("Test case timeout was reached while waiting for the stream response from the Service. Timeout was: {0}", ScenarioTestHelpers.TestTimeout)); clientReceiver.ReceiveStreamInvoked.Reset(); // Upload the stream while we are downloading a different stream uploadStream = new FlowControlledStream(); uploadStream.ReadThrottle = TimeSpan.FromMilliseconds(500); uploadStream.StreamDuration = TimeSpan.FromSeconds(1); client.UploadStream(uploadStream); client.StopPushingStream(); // Waiting on ReceiveStreamCompleted from the ClientReceiver. Assert.True(clientReceiver.ReceiveStreamCompleted.WaitOne(ScenarioTestHelpers.TestTimeout), String.Format("Test case timeout was reached while waiting for the stream response from the Service to be completed. Timeout was: {0}", ScenarioTestHelpers.TestTimeout)); clientReceiver.ReceiveStreamCompleted.Reset(); // Getting results from server via callback. client.GetLog(); Assert.True(clientReceiver.LogReceived.WaitOne(ScenarioTestHelpers.TestTimeout), String.Format("Test case timeout was reached while waiting for the Logging from the Service to be received. Timeout was: {0}", ScenarioTestHelpers.TestTimeout)); // *** VALIDATE *** \\ Assert.True(clientReceiver.ServerLog.Count > 0, "The logging done by the Server was not returned via the Callback."); // *** CLEANUP *** \\ ((ICommunicationObject)client).Close(); channelFactory.Close(); } finally { // *** ENSURE CLEANUP *** \\ ScenarioTestHelpers.CloseCommunicationObjects((ICommunicationObject)client, channelFactory); clientReceiver.Dispose(); } }
public static void WebSocket_Https_Duplex_TextStreamed() { TextMessageEncodingBindingElement textMessageEncodingBindingElement = null; HttpsTransportBindingElement httpsTransportBindingElement = null; CustomBinding binding = null; ClientReceiver clientReceiver = null; InstanceContext context = null; DuplexChannelFactory<IWSDuplexService> channelFactory = null; IWSDuplexService client = null; FlowControlledStream uploadStream = null; try { // *** SETUP *** \\ textMessageEncodingBindingElement = new TextMessageEncodingBindingElement(); httpsTransportBindingElement = new HttpsTransportBindingElement() { MaxReceivedMessageSize = ScenarioTestHelpers.DefaultMaxReceivedMessageSize, MaxBufferSize = ScenarioTestHelpers.DefaultMaxReceivedMessageSize, TransferMode = TransferMode.Streamed }; httpsTransportBindingElement.WebSocketSettings.TransportUsage = WebSocketTransportUsage.Always; binding = new CustomBinding(textMessageEncodingBindingElement, httpsTransportBindingElement); clientReceiver = new ClientReceiver(); context = new InstanceContext(clientReceiver); channelFactory = new DuplexChannelFactory<IWSDuplexService>(context, binding, Endpoints.WebSocketHttpsDuplexTextStreamed_Address); client = channelFactory.CreateChannel(); // *** EXECUTE *** \\ using (Stream stream = client.DownloadStream()) { int readResult; // Read from the stream, 1000 bytes at a time. byte[] buffer = new byte[1000]; do { readResult = stream.Read(buffer, 0, buffer.Length); } while (readResult != 0); } uploadStream = new FlowControlledStream(); uploadStream.ReadThrottle = TimeSpan.FromMilliseconds(500); uploadStream.StreamDuration = TimeSpan.FromSeconds(1); client.UploadStream(uploadStream); client.StartPushingStream(); // Wait for the callback to get invoked before telling the service to stop streaming. // This ensures we can read from the stream on the callback while the NCL layer at the service // is still writing the bytes from the stream to the wire. // This will deadlock if the transfer mode is buffered because the callback will wait for the // stream, and the NCL layer will continue to buffer the stream until it reaches the end. Assert.True(clientReceiver.ReceiveStreamInvoked.WaitOne(ScenarioTestHelpers.TestTimeout), "Test case timeout was reached while waiting for the stream response from the Service."); clientReceiver.ReceiveStreamInvoked.Reset(); // Upload the stream while we are downloading a different stream uploadStream = new FlowControlledStream(); uploadStream.ReadThrottle = TimeSpan.FromMilliseconds(500); uploadStream.StreamDuration = TimeSpan.FromSeconds(1); client.UploadStream(uploadStream); client.StopPushingStream(); // Waiting on ReceiveStreamCompleted from the ClientReceiver. Assert.True(clientReceiver.ReceiveStreamCompleted.WaitOne(ScenarioTestHelpers.TestTimeout), "Test case timeout was reached while waiting for the stream response from the Service to be completed."); clientReceiver.ReceiveStreamCompleted.Reset(); // *** VALIDATE *** \\ // Validation is based on no exceptions being thrown. // *** CLEANUP *** \\ ((ICommunicationObject)client).Close(); channelFactory.Close(); } finally { // *** ENSURE CLEANUP *** \\ ScenarioTestHelpers.CloseCommunicationObjects((ICommunicationObject)client, channelFactory); clientReceiver.Dispose(); } }
public static void WebSocket_Https_Duplex_BinaryStreamed() { BinaryMessageEncodingBindingElement binaryMessageEncodingBindingElement = null; HttpsTransportBindingElement httpsTransportBindingElement = null; CustomBinding binding = null; ClientReceiver clientReceiver = null; InstanceContext context = null; DuplexChannelFactory <IWSDuplexService> channelFactory = null; IWSDuplexService client = null; FlowControlledStream uploadStream = null; try { // *** SETUP *** \\ binaryMessageEncodingBindingElement = new BinaryMessageEncodingBindingElement(); httpsTransportBindingElement = new HttpsTransportBindingElement(); httpsTransportBindingElement.WebSocketSettings.TransportUsage = WebSocketTransportUsage.Always; httpsTransportBindingElement.MaxReceivedMessageSize = ScenarioTestHelpers.DefaultMaxReceivedMessageSize; httpsTransportBindingElement.MaxBufferSize = ScenarioTestHelpers.DefaultMaxReceivedMessageSize; httpsTransportBindingElement.TransferMode = TransferMode.Streamed; binding = new CustomBinding(binaryMessageEncodingBindingElement, httpsTransportBindingElement); clientReceiver = new ClientReceiver(); context = new InstanceContext(clientReceiver); channelFactory = new DuplexChannelFactory <IWSDuplexService>(context, binding, Endpoints.WebSocketHttpsDuplexBinaryStreamed_Address); client = channelFactory.CreateChannel(); // *** EXECUTE *** \\ using (Stream stream = client.DownloadStream()) { int readResult; // Read from the stream, 1000 bytes at a time. byte[] buffer = new byte[1000]; do { readResult = stream.Read(buffer, 0, buffer.Length); }while (readResult != 0); } uploadStream = new FlowControlledStream(); uploadStream.ReadThrottle = TimeSpan.FromMilliseconds(500); uploadStream.StreamDuration = TimeSpan.FromSeconds(1); client.UploadStream(uploadStream); client.StartPushingStream(); // Wait for the callback to get invoked before telling the service to stop streaming. // This ensures we can read from the stream on the callback while the NCL layer at the service // is still writing the bytes from the stream to the wire. // This will deadlock if the transfer mode is buffered because the callback will wait for the // stream, and the NCL layer will continue to buffer the stream until it reaches the end. Assert.True(clientReceiver.ReceiveStreamInvoked.WaitOne(ScenarioTestHelpers.TestTimeout), "Test case timeout was reached while waiting for the stream response from the Service."); clientReceiver.ReceiveStreamInvoked.Reset(); // Upload the stream while we are downloading a different stream uploadStream = new FlowControlledStream(); uploadStream.ReadThrottle = TimeSpan.FromMilliseconds(500); uploadStream.StreamDuration = TimeSpan.FromSeconds(1); client.UploadStream(uploadStream); client.StopPushingStream(); // Waiting on ReceiveStreamCompleted from the ClientReceiver. clientReceiver.ReceiveStreamCompleted.WaitOne(); clientReceiver.ReceiveStreamCompleted.Reset(); // *** VALIDATE *** \\ // Validation is based on no exceptions being thrown. // *** CLEANUP *** \\ ((ICommunicationObject)client).Close(); channelFactory.Close(); } finally { // *** ENSURE CLEANUP *** \\ ScenarioTestHelpers.CloseCommunicationObjects((ICommunicationObject)client, channelFactory); clientReceiver.Dispose(); } }