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 static void WebSocket_Https_RequestReply_Buffered_KeepAlive(NetHttpMessageEncoding messageEncoding) { EndpointAddress endpointAddress; NetHttpsBinding binding = null; ChannelFactory <IWSRequestReplyService> channelFactory = null; IWSRequestReplyService client = null; try { // *** SETUP *** \\ binding = new NetHttpsBinding() { MaxReceivedMessageSize = ScenarioTestHelpers.SixtyFourMB, MaxBufferSize = ScenarioTestHelpers.SixtyFourMB, }; binding.WebSocketSettings.TransportUsage = WebSocketTransportUsage.Always; binding.WebSocketSettings.KeepAliveInterval = TimeSpan.FromSeconds(2); binding.TransferMode = TransferMode.Buffered; binding.MessageEncoding = messageEncoding; endpointAddress = new EndpointAddress(Endpoints.WebSocketHttpsRequestReplyBuffered_Address + Enum.GetName(typeof(NetHttpMessageEncoding), messageEncoding)); channelFactory = new ChannelFactory <IWSRequestReplyService>(binding, endpointAddress); client = channelFactory.CreateChannel(); // *** EXECUTE *** \\ // Invoking DownloadData string result = client.DownloadData(); // Invoking UploadData client.UploadData(ScenarioTestHelpers.CreateInterestingString(123)); // *** 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); } }