public static void BasicHttp_DefaultSettings_Echo_RoundTrips_String_Buffered() { 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.Buffered; factory = new ChannelFactory <IWcfService>(binding, new EndpointAddress(Endpoints.HttpBaseAddress_Basic)); serviceProxy = factory.CreateChannel(); stream = StringToStream(testString); // *** EXECUTE *** \\ var returnStream = serviceProxy.EchoStream(stream); var result = StreamToString(returnStream); // *** VALIDATE *** \\ Assert.Equal(testString, result); // *** CLEANUP *** \\ ((ICommunicationObject)serviceProxy).Close(); factory.Close(); } finally { // *** ENSURE CLEANUP *** \\ ScenarioTestHelpers.CloseCommunicationObjects((ICommunicationObject)serviceProxy, factory); } }
[ActiveIssue(832)] // Windows Stream Security is not supported in NET Native #endif public static void NetTcp_TransportSecurity_Streamed_RoundTrips_String() { string testString = "Hello"; NetTcpBinding binding = null; ChannelFactory <IWcfService> factory = null; IWcfService serviceProxy = null; Stream stream = null; try { // *** SETUP *** \\ binding = new NetTcpBinding(SecurityMode.Transport); binding.TransferMode = TransferMode.Streamed; factory = new ChannelFactory <IWcfService>(binding, new EndpointAddress(Endpoints.Tcp_Transport_Security_Streamed_Address)); serviceProxy = factory.CreateChannel(); stream = StringToStream(testString); // *** EXECUTE *** \\ var returnStream = serviceProxy.EchoStream(stream); 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() { 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.EchoStream(stream); 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 DefaultSettings_Echo_RoundTrips_String_Buffered() { string testString = "Hello"; BasicHttpBinding binding = new BasicHttpBinding(BasicHttpSecurityMode.None); binding.TransferMode = TransferMode.Buffered; ChannelFactory <IWcfService> factory = new ChannelFactory <IWcfService>(binding, new EndpointAddress(Endpoints.HttpBaseAddress_Basic)); IWcfService serviceProxy = factory.CreateChannel(); try { Stream stream = StringToStream(testString); var returnStream = serviceProxy.EchoStream(stream); var result = StreamToString(returnStream); Assert.Equal(testString, result); } finally { if (factory != null && factory.State != CommunicationState.Closed) { factory.Abort(); } } }
public static void NetTcp_TransportSecurity_Streamed_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"; NetTcpBinding binding = null; ChannelFactory <IWcfService> factory = null; IWcfService serviceProxy = null; Stream stream = null; try { // *** SETUP *** \\ binding = new NetTcpBinding(SecurityMode.Transport); binding.TransferMode = TransferMode.Streamed; factory = new ChannelFactory <IWcfService>(binding, new EndpointAddress(Endpoints.Tcp_Transport_Security_Streamed_Address)); serviceProxy = factory.CreateChannel(); stream = StringToStream(testString); // *** EXECUTE *** \\ var returnStream = serviceProxy.EchoStream(stream); 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 NetTcp_TransportSecurity_Streamed_MultipleReads() { string testString = ScenarioTestHelpers.CreateInterestingString(20001); NetTcpBinding binding = null; ChannelFactory <IWcfService> factory = null; IWcfService serviceProxy = null; Stream stream = null; try { // *** SETUP *** \\ binding = new NetTcpBinding(SecurityMode.Transport); binding.TransferMode = TransferMode.Streamed; factory = new ChannelFactory <IWcfService>(binding, new EndpointAddress(Endpoints.Tcp_Transport_Security_Streamed_Address)); serviceProxy = factory.CreateChannel(); stream = StringToStream(testString); // *** EXECUTE *** \\ var returnStream = serviceProxy.EchoStream(stream); var ms = new MemoryStream((int)stream.Length); var buffer = new byte[10]; int bytesRead = 0; while ((bytesRead = returnStream.ReadAsync(buffer, 0, buffer.Length).Result) != 0) { ms.Write(buffer, 0, bytesRead); } ms.Position = 0; var result = StreamToString(ms); // *** VALIDATE *** \\ Assert.Equal(testString, result); // *** CLEANUP *** \\ ((ICommunicationObject)serviceProxy).Close(); factory.Close(); } finally { // *** ENSURE CLEANUP *** \\ ScenarioTestHelpers.CloseCommunicationObjects((ICommunicationObject)serviceProxy, factory); } }
public static void CustomTextMessageEncoder_Http_RequestReply_Streamed() { // 84K, larger than any buffers, but won't allocate in LOH int streamKBytes = 84; int streamLength = 1024 * streamKBytes; int lowestPrintable = ' '; int printableRange = '~' - lowestPrintable; ChannelFactory <IWcfService> factory = null; IWcfService serviceProxy = null; Stream stream = null; try { // *** SETUP *** \\ CustomBinding binding = new CustomBinding(new CustomTextMessageBindingElement(Encoding.UTF8.WebName), new HttpTransportBindingElement { MaxReceivedMessageSize = ScenarioTestHelpers.SixtyFourMB, MaxBufferSize = ScenarioTestHelpers.SixtyFourMB, TransferMode = TransferMode.Streamed }); factory = new ChannelFactory <IWcfService>(binding, new EndpointAddress(Endpoints.CustomTextEncoderStreamed_Address)); serviceProxy = factory.CreateChannel(); byte[] requestBytes = new byte[streamLength]; RandomNumberGenerator rnd = RandomNumberGenerator.Create(); int pos = 0; for (int i = 0; i < streamKBytes; i++) { byte[] tempBuffer = new byte[1024]; rnd.GetBytes(tempBuffer); for (int j = 0; j < 1024; j++) { byte val = tempBuffer[j]; if (val < ' ' || val > '~') { // Force the value to be between ' ' and '~' int temp1 = val % printableRange; val = (byte)(temp1 + lowestPrintable); } requestBytes[pos++] = val; } } stream = new MemoryStream(requestBytes); // *** EXECUTE *** \\ var returnStream = serviceProxy.EchoStream(stream); // *** VALIDATE *** \\ MemoryStream ms = new MemoryStream(streamLength); returnStream.CopyTo(ms); Assert.True(streamLength == ms.Length, String.Format("Expected returned stream length = {0}, actual = {1}", streamLength, ms.Length)); ArraySegment <byte> returnedByteArraySegment; ms.TryGetBuffer(out returnedByteArraySegment); Assert.True(requestBytes.SequenceEqual(returnedByteArraySegment.Array), "Returned bytes are different than sent bytes"); // *** CLEANUP *** \\ ((ICommunicationObject)serviceProxy).Close(); factory.Close(); } finally { // *** ENSURE CLEANUP *** \\ ScenarioTestHelpers.CloseCommunicationObjects((ICommunicationObject)serviceProxy, factory); } }