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 ClientBaseOfT_Sync_RoundTrip_Check_CommunicationState() { CustomBinding customBinding = new CustomBinding(); customBinding.Elements.Add(new TextMessageEncodingBindingElement()); customBinding.Elements.Add(new HttpTransportBindingElement()); MyClientBase client = new MyClientBase(customBinding, new EndpointAddress(Endpoints.HttpSoap12_Address)); Assert.Equal(CommunicationState.Created, client.State); IWcfServiceGenerated serviceProxy = client.ChannelFactory.CreateChannel(); Assert.Equal(CommunicationState.Opened, client.State); try { string result = serviceProxy.Echo("Hello"); Assert.Equal(CommunicationState.Opened, client.State); ((ICommunicationObject)client).Close(); Assert.Equal(CommunicationState.Closed, client.State); } finally { // normally we'd also check for if (client != null && client.State != CommuncationState.Closed), // but this is a test and it'd be good to have the Abort happen and the channel is still Closed if (client != null) { client.Abort(); Assert.Equal(CommunicationState.Closed, client.State); } } }
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 ClientBaseOfT_Sync_RoundTrip_Call_Using_NetTcpTransport() { // This test verifies ClientBase<T> can be used to create a proxy and invoke an operation over Tcp // (request reply over Tcp) // This test verifies ClientBase<T> can be used to create a proxy and invoke an operation over Http CustomBinding binding = new CustomBinding( new TextMessageEncodingBindingElement(), new TcpTransportBindingElement()); MyClientBase client = new MyClientBase(binding, new EndpointAddress(Endpoints.Tcp_CustomBinding_NoSecurity_Text_Address)); IWcfServiceGenerated serviceProxy = client.ChannelFactory.CreateChannel(); try { string result = serviceProxy.Echo("Hello"); Assert.Equal("Hello", result); } finally { if (client != null && client.State != CommunicationState.Closed) { client.Abort(); } } }
public static void ClientBaseOfT_Abort_Aborts_Factory_And_Proxy() { MyClientBase client = null; IWcfServiceGenerated serviceProxy = null; ChannelFactory <IWcfServiceGenerated> factory = null; try { // *** SETUP *** \\ CustomBinding customBinding = new CustomBinding(); customBinding.Elements.Add(new TextMessageEncodingBindingElement()); customBinding.Elements.Add(new HttpTransportBindingElement()); string endpoint = Endpoints.HttpSoap12_Address; client = new MyClientBase(customBinding, new EndpointAddress(endpoint)); factory = client.ChannelFactory; // *** EXECUTE *** \\ // Explicitly open the ClientBase to follow general WCF guidelines ((ICommunicationObject)client).Open(); // Use the internal proxy generated by ClientBase to most resemble how svcutil-generated code works. // Customers cannot normally access this protected member explicitly, but the generated code uses it. serviceProxy = client.Proxy; // *** EXECUTE *** \\ client.Abort(); // *** VALIDATE *** \\ // Closing the ClientBase closes the internal channel and factory Assert.True(CommunicationState.Closed == client.State, String.Format("Expected client state to be Closed but actual was '{0}'", client.State)); // Closing the ClientBase also closes the internal channel Assert.True(CommunicationState.Closed == ((ICommunicationObject)serviceProxy).State, String.Format("Expected proxy state to be Closed but actual was '{0}'", ((ICommunicationObject)serviceProxy).State)); // Closing the ClientBase also closes the channel factory Assert.True(CommunicationState.Closed == factory.State, String.Format("Expected channel factory state to be Closed but actual was '{0}'", factory.State)); } finally { // *** ENSURE CLEANUP *** \\ ScenarioTestHelpers.CloseCommunicationObjects((ICommunicationObject)serviceProxy, client, factory); } }
public static void OperationContextScope_HttpRequestCustomMessageHeader_RoundTrip_Verify() { BasicHttpBinding binding = new BasicHttpBinding(); MyClientBase <IWcfService> client = new MyClientBase <IWcfService>(binding, new EndpointAddress(Endpoints.HttpBaseAddress_Basic)); IWcfService serviceProxy = client.ChannelFactory.CreateChannel(); string customHeaderName = "OperationContextScopeCustomHeader"; string customHeaderNS = "http://tempuri.org/OperationContextScope_HttpRequestCustomMessageHeader_RoundTrip_Verify"; string customHeaderValue = "CustomHappyValue"; try { using (OperationContextScope scope = new OperationContextScope((IContextChannel)serviceProxy)) { MessageHeader header = MessageHeader.CreateHeader( customHeaderName, customHeaderNS, customHeaderValue ); OperationContext.Current.OutgoingMessageHeaders.Add(header); Dictionary <string, string> incomingMessageHeaders = serviceProxy.GetIncomingMessageHeaders(); string result = GetHeader(customHeaderName, customHeaderNS, incomingMessageHeaders); Assert.Equal(customHeaderValue, result); } //Call outside of scope should not have the custom header Dictionary <string, string> outofScopeIncomingMessageHeaders = serviceProxy.GetIncomingMessageHeaders(); string outofScopeResult = GetHeader(customHeaderName, customHeaderNS, outofScopeIncomingMessageHeaders); Assert.True(string.Empty == outofScopeResult, string.Format("Expect call out of the OperationContextScope does not have the custom header {0}", customHeaderName)); ((ICommunicationObject)client).Close(); } finally { if (client != null && client.State != CommunicationState.Closed) { client.Abort(); } } }
public static void ClientMessageInspector_Verify_Invoke() { // This test verifies ClientMessageInspector can be added to the client endpoint behaviors // and this is it called properly when a message is sent. CustomBinding customBinding = new CustomBinding(); customBinding.Elements.Add(new TextMessageEncodingBindingElement()); customBinding.Elements.Add(new HttpTransportBindingElement()); MyClientBase client = new MyClientBase(customBinding, new EndpointAddress(Endpoints.DefaultCustomHttp_Address)); // Add the ClientMessageInspector and give it an instance where it can record what happens when it is called. ClientMessageInspectorData data = new ClientMessageInspectorData(); client.Endpoint.EndpointBehaviors.Add(new ClientMessageInspectorBehavior(data)); try { IWcfServiceGenerated serviceProxy = client.ChannelFactory.CreateChannel(); // This proxy call should invoke the client message inspector string result = serviceProxy.Echo("Hello"); Assert.Equal("Hello", result); Assert.True(data.BeforeSendRequestCalled, "BeforeSendRequest should have been called"); Assert.True(data.Request != null, "Did not call pass Request to BeforeSendRequest"); Assert.True(data.Channel != null, "Did not call pass Channel to BeforeSendRequest"); Assert.True(data.AfterReceiveReplyCalled, "AfterReceiveReplyCalled should have been called"); Assert.True(data.Reply != null, "Did not call pass Reply to AfterReceiveReplyCalled"); } finally { if (client != null && client.State != CommunicationState.Closed) { client.Abort(); } } }
public static void ClientBaseOfT_Sync_RoundTrip_Check_CommunicationState() { MyClientBase client = null; IWcfServiceGenerated serviceProxy = null; try { // *** SETUP *** \\ CustomBinding customBinding = new CustomBinding(); customBinding.Elements.Add(new TextMessageEncodingBindingElement()); customBinding.Elements.Add(new HttpTransportBindingElement()); client = new MyClientBase(customBinding, new EndpointAddress(Endpoints.HttpSoap12_Address)); // *** VALIDATE *** \\ Assert.Equal(CommunicationState.Created, client.State); serviceProxy = client.ChannelFactory.CreateChannel(); // *** VALIDATE *** \\ Assert.Equal(CommunicationState.Opened, client.State); // *** EXECUTE *** \\ string result = serviceProxy.Echo("Hello"); // *** VALIDATE *** \\ Assert.Equal(CommunicationState.Opened, client.State); // *** CLEANUP *** \\ ((ICommunicationObject)client).Close(); ((ICommunicationObject)serviceProxy).Close(); // *** VALIDATE *** \\ Assert.Equal(CommunicationState.Closed, client.State); } finally { // normally we'd also check for if (client != null && client.State != CommuncationState.Closed), // but this is a test and it'd be good to have the Abort happen and the channel is still Closed if (client != null) { client.Abort(); Assert.Equal(CommunicationState.Closed, client.State); } // *** ENSURE CLEANUP *** \\ ScenarioTestHelpers.CloseCommunicationObjects((ICommunicationObject)serviceProxy, (ICommunicationObject)client); } }
public static void OperationContextScope_HttpRequestCustomMessageHeader_RoundTrip_Verify() { BasicHttpBinding binding = new BasicHttpBinding(); MyClientBase<IWcfService> client = new MyClientBase<IWcfService>(binding, new EndpointAddress(Endpoints.HttpBaseAddress_Basic)); IWcfService serviceProxy = client.ChannelFactory.CreateChannel(); string customHeaderName = "OperationContextScopeCustomHeader"; string customHeaderNS = "http://tempuri.org/OperationContextScope_HttpRequestCustomMessageHeader_RoundTrip_Verify"; string customHeaderValue = "CustomHappyValue"; try { using (OperationContextScope scope = new OperationContextScope((IContextChannel)serviceProxy)) { MessageHeader header = MessageHeader.CreateHeader( customHeaderName, customHeaderNS, customHeaderValue ); OperationContext.Current.OutgoingMessageHeaders.Add(header); Dictionary<string, string> incomingMessageHeaders = serviceProxy.GetIncomingMessageHeaders(); string result = GetHeader(customHeaderName, customHeaderNS, incomingMessageHeaders); Assert.Equal(customHeaderValue, result); } //Call outside of scope should not have the custom header Dictionary<string, string> outofScopeIncomingMessageHeaders = serviceProxy.GetIncomingMessageHeaders(); string outofScopeResult = GetHeader(customHeaderName, customHeaderNS, outofScopeIncomingMessageHeaders); Assert.True(string.Empty == outofScopeResult, string.Format("Expect call out of the OperationContextScope does not have the custom header {0}", customHeaderName)); ((ICommunicationObject)client).Close(); } finally { if (client != null && client.State != CommunicationState.Closed) { client.Abort(); } } }