public static void MessageProperty_HttpRequestMessageProperty_RoundTrip_Verify() { CustomBinding customBinding = new CustomBinding(); customBinding.Elements.Add(new TextMessageEncodingBindingElement()); customBinding.Elements.Add(new HttpTransportBindingElement()); MyClientBase <IWcfService> client = new MyClientBase <IWcfService>(customBinding, new EndpointAddress(Endpoints.DefaultCustomHttp_Address)); client.Endpoint.EndpointBehaviors.Add(new ClientMessagePropertyBehavior()); try { IWcfService serviceProxy = client.ChannelFactory.CreateChannel(); TestHttpRequestMessageProperty property = serviceProxy.EchoHttpRequestMessageProperty(); Assert.NotNull(property); Assert.True(property.SuppressEntityBody == false, "Expected SuppressEntityBody to be 'false'"); Assert.Equal("POST", property.Method); Assert.Equal("My%20address", property.QueryString); Assert.True(property.Headers.Count > 0, "TestHttpRequestMessageProperty.Headers should not have empty headers"); Assert.Equal("my value", property.Headers["customer"]); } finally { if (client != null && client.State != CommunicationState.Closed) { client.Abort(); } } }
public static void MessageProperty_HttpRequestMessageProperty_RoundTrip_Verify() { StringBuilder errorBuilder = new StringBuilder(); try { CustomBinding customBinding = new CustomBinding(); customBinding.Elements.Add(new TextMessageEncodingBindingElement()); customBinding.Elements.Add(new HttpTransportBindingElement()); MyClientBase <IWcfService> client = new MyClientBase <IWcfService>(customBinding, new EndpointAddress(BaseAddress.HttpBaseAddress)); client.Endpoint.EndpointBehaviors.Add(new ClientMessagePropertyBehavior()); IWcfService serviceProxy = client.ChannelFactory.CreateChannel(); TestHttpRequestMessageProperty property = serviceProxy.EchoHttpRequestMessageProperty(); if (property == null) { errorBuilder.AppendLine("Null HttpRequestMessageProperty returned"); } else { if (property.SuppressEntityBody != false) { errorBuilder.AppendLine("Expected SuppressEntityBody: false, actual: " + property.SuppressEntityBody); } if (property.Method != "POST") { errorBuilder.AppendLine("Expected Method: POST, actual: " + property.Method); } if (property.QueryString != "My%20address") { errorBuilder.AppendLine("Expected QueryString: My%20address, actual: " + property.QueryString); } if (property.Headers.Count == 0) { errorBuilder.AppendLine("Headers are empty"); } else if (property.Headers["customer"] != "my value") { errorBuilder.AppendLine("Expected customer header: my value, actual: " + property.Headers["customer"]); } } } catch (Exception ex) { errorBuilder.AppendLine(String.Format("Unexpected exception was caught: {0}", ex.ToString())); } Assert.True(errorBuilder.Length == 0, String.Format("Test Scenario: MessageProperty_HttpRequestMessageProperty_RoundTrip_Verify FAILED with the following errors: {0}", errorBuilder)); }
public static void ClientBaseOfT_ServiceEndpointCtor_ExtractedCntrctDscrip() { MyClientBase <IWcfService> client = null; IWcfService serviceProxy = null; try { // *** SETUP *** \\ CustomBinding customBinding = new CustomBinding(); customBinding.Elements.Add(new TextMessageEncodingBindingElement()); customBinding.Elements.Add(new HttpTransportBindingElement()); string endpoint = Endpoints.DefaultCustomHttp_Address; client = new MyClientBase <IWcfService>(customBinding, new EndpointAddress(endpoint)); // Extract the ContractDescription from the channel factory. ContractDescription cd = client.ChannelFactory.Endpoint.Contract; // Use the ContractDescription to create a new ServiceEndpoint ServiceEndpoint serviceEndpoint = new ServiceEndpoint(cd, customBinding, new EndpointAddress(endpoint)); client = new MyClientBase <IWcfService>(serviceEndpoint); client.Endpoint.EndpointBehaviors.Add(new ClientMessagePropertyBehavior()); serviceProxy = client.ChannelFactory.CreateChannel(); // *** EXECUTE *** \\ TestHttpRequestMessageProperty property = serviceProxy.EchoHttpRequestMessageProperty(); // *** VALIDATE *** \\ Assert.NotNull(property); Assert.True(property.SuppressEntityBody == false, "Expected SuppressEntityBody to be 'false'"); Assert.Equal("POST", property.Method); Assert.Equal("My%20address", property.QueryString); Assert.True(property.Headers.Count > 0, "TestHttpRequestMessageProperty.Headers should not have empty headers"); Assert.Equal("my value", property.Headers["customer"]); // *** CLEANUP *** \\ ((ICommunicationObject)client).Close(); ((ICommunicationObject)serviceProxy).Close(); } finally { // *** ENSURE CLEANUP *** \\ ScenarioTestHelpers.CloseCommunicationObjects((ICommunicationObject)serviceProxy, (ICommunicationObject)client); } }