Ejemplo n.º 1
0
    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)

        MyClientBase         client       = null;
        IWcfServiceGenerated serviceProxy = null;

        try
        {
            // *** SETUP *** \\
            CustomBinding binding = new CustomBinding(new TextMessageEncodingBindingElement(), new TcpTransportBindingElement());

            client       = new MyClientBase(binding, new EndpointAddress(Endpoints.Tcp_CustomBinding_NoSecurity_Text_Address));
            serviceProxy = client.ChannelFactory.CreateChannel();

            // *** EXECUTE *** \\
            string result = serviceProxy.Echo("Hello");

            // *** VALIDATE *** \\
            Assert.Equal("Hello", result);

            // *** CLEANUP *** \\
            ((ICommunicationObject)client).Close();
            ((ICommunicationObject)serviceProxy).Close();
        }
        finally
        {
            // *** ENSURE CLEANUP *** \\
            ScenarioTestHelpers.CloseCommunicationObjects((ICommunicationObject)serviceProxy, (ICommunicationObject)client);
        }
    }
    public static void ClientBaseOfT_ClientCredentials()
    {
        MyClientBase      client            = null;
        ClientCredentials clientCredentials = 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));

            // *** EXECUTE *** \\
            clientCredentials = client.ClientCredentials;

            // *** VALIDATE *** \\
            Assert.True(clientCredentials != null, "ClientCredentials should not be null");
            Assert.True(clientCredentials.ClientCertificate != null, "ClientCredentials.ClientCertificate should not be null");
            Assert.True(clientCredentials.ServiceCertificate != null, "ClientCredentials.ServiceCertificate should not be null");
            Assert.True(clientCredentials.HttpDigest != null, "ClientCredentials.HttpDigest should not be null");

            // *** CLEANUP *** \\
            ((ICommunicationObject)client).Close();
        }
        finally
        {
            // *** ENSURE CLEANUP *** \\
            ScenarioTestHelpers.CloseCommunicationObjects(client);
        }
    }
Ejemplo n.º 3
0
    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();
            }
        }
    }
Ejemplo n.º 4
0
    public static void ClientBaseOfT_Call()
    {
        // This test verifies ClientBase<T> can be used to create a proxy and invoke an operation
        StringBuilder errorBuilder = new StringBuilder();

        try
        {
            CustomBinding customBinding = new CustomBinding();
            customBinding.Elements.Add(new TextMessageEncodingBindingElement());
            customBinding.Elements.Add(new HttpTransportBindingElement());

            MyClientBase         client       = new MyClientBase(customBinding, new EndpointAddress(BaseAddress.HttpBaseAddress));
            IWcfServiceGenerated serviceProxy = client.ChannelFactory.CreateChannel();

            string result = serviceProxy.Echo("Hello");
            if (!string.Equals(result, "Hello"))
            {
                errorBuilder.AppendLine(String.Format("Expected response from Service: {0} Actual was: {1}", "Hello", result));
            }
        }
        catch (Exception ex)
        {
            errorBuilder.AppendLine(String.Format("Unexpected exception was caught: {0}", ex.ToString()));
        }

        Assert.True(errorBuilder.Length == 0, string.Format("Test Scenario: ClientBaseOfTCall FAILED with the following errors: {0}", errorBuilder));
    }
Ejemplo n.º 5
0
    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();
            }
        }
    }
Ejemplo n.º 6
0
    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);
            }
        }
    }
Ejemplo n.º 7
0
    // Helper method to validate that service contract T is correct.
    // This helper uses ClientBase<T> to construct the ContractDescription.
    // The 'expectedOperations' describes the operations we expect to find in that contract.
    public static string ValidateContractDescription <T>(ContractDescriptionData expectedContract) where T : class
    {
        OperationDescriptionData[] expectedOperations = expectedContract.Operations;

        StringBuilder errorBuilder = new StringBuilder();

        try
        {
            CustomBinding customBinding = new CustomBinding();
            customBinding.Elements.Add(new TextMessageEncodingBindingElement());
            customBinding.Elements.Add(new HttpTransportBindingElement());

            MyClientBase <T>    client   = new MyClientBase <T>(customBinding, new EndpointAddress(address));
            ContractDescription contract = client.Endpoint.Contract;

            string results = ValidateContractDescription(contract, typeof(T), expectedContract);
            if (results != null)
            {
                errorBuilder.AppendLine(results);
            }
        }
        catch (Exception ex)
        {
            errorBuilder.AppendLine(String.Format("Unexpected exception was caught: {0}", ex.ToString()));
        }

        return(errorBuilder.Length == 0 ? null : errorBuilder.ToString());
    }
Ejemplo n.º 8
0
    public static void ClientBaseOfT_ClientCredentials()
    {
        MyClientBase client = null;
        ClientCredentials clientCredentials = 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));

            // *** EXECUTE *** \\
            clientCredentials = client.ClientCredentials;

            // *** VALIDATE *** \\
            Assert.True(clientCredentials != null, "ClientCredentials should not be null");
            Assert.True(clientCredentials.ClientCertificate != null, "ClientCredentials.ClientCertificate should not be null");
            Assert.True(clientCredentials.ServiceCertificate != null, "ClientCredentials.ServiceCertificate should not be null");
            Assert.True(clientCredentials.HttpDigest != null, "ClientCredentials.HttpDigest should not be null");

            // *** CLEANUP *** \\
            ((ICommunicationObject)client).Close();

        }
        finally
        {
            // *** ENSURE CLEANUP *** \\
            ScenarioTestHelpers.CloseCommunicationObjects(client);
        }
    }
    public static void TestAccessFaultContractInfo()
    {
        MyClientBase <IWcfService> client = null;
        IWcfService serviceProxy          = null;
        string      action = @"http://tempuri.org/IWcfService/TestFaultFaultDetailFault";
        Type        detail = typeof(FaultDetail);

        try
        {
            // *** SETUP *** \\
            CustomBinding customBinding = new CustomBinding();
            customBinding.Elements.Add(new TextMessageEncodingBindingElement());
            customBinding.Elements.Add(new HttpTransportBindingElement());

            client = new MyClientBase <IWcfService>(customBinding, new EndpointAddress(Endpoints.DefaultCustomHttp_Address));
            client.Endpoint.EndpointBehaviors.Add(new TestFaultContractInfosBehavior());
            serviceProxy = client.ChannelFactory.CreateChannel();

            // *** EXECUTE *** \\
            var input = new object[] { new FaultDetail(), new KnownTypeA() };
            // Use exiting service as we only need to verify FaultContractInfo can be accessed from ClientOperation
            serviceProxy.TestFaultWithKnownType(null, input);

            //Verify
            Assert.True(TestFaultContractInfosBehavior.testFaultWithKnownTypeClientOp != null, "Expected testFaultWithKnownTypeClientOp is NOT null");
            Assert.True(TestFaultContractInfosBehavior.testFaultWithKnownTypeClientOp.FaultContractInfos.Count == 1, string.Format("expected FaultContractInfos count is 1, actual: {0}", TestFaultContractInfosBehavior.testFaultWithKnownTypeClientOp.FaultContractInfos.Count));
            Assert.True(TestFaultContractInfosBehavior.testFaultWithKnownTypeClientOp.FaultContractInfos[0].Action == action, string.Format("expected FaultContractInfo Action is {0}, actual: {1}", action, TestFaultContractInfosBehavior.testFaultWithKnownTypeClientOp.FaultContractInfos[0].Action));
            Assert.True(TestFaultContractInfosBehavior.testFaultWithKnownTypeClientOp.FaultContractInfos[0].Detail == detail, string.Format("expected FaultContractInfo Detail is {0}, actual: {1}", detail.ToString(), TestFaultContractInfosBehavior.testFaultWithKnownTypeClientOp.FaultContractInfos[0].Detail.ToString()));
        }
        finally
        {
            // *** ENSURE CLEANUP *** \\
            ScenarioTestHelpers.CloseCommunicationObjects((ICommunicationObject)serviceProxy, (ICommunicationObject)client);
        }
    }
Ejemplo n.º 10
0
    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(); 
                }
                }
                }
Ejemplo n.º 11
0
    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.
        StringBuilder errorBuilder = new StringBuilder();

        try
        {
            CustomBinding customBinding = new CustomBinding();
            customBinding.Elements.Add(new TextMessageEncodingBindingElement());
            customBinding.Elements.Add(new HttpTransportBindingElement());

            MyClientBase client = new MyClientBase(customBinding, new EndpointAddress(BaseAddress.HttpBaseAddress));

            // 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));
            IWcfServiceGenerated serviceProxy = client.ChannelFactory.CreateChannel();

            // This proxy call should invoke the client message inspector
            string result = serviceProxy.Echo("Hello");
            if (!string.Equals(result, "Hello"))
            {
                errorBuilder.AppendLine(String.Format("Expected response from Service: {0} Actual was: {1}", "Hello", result));
            }

            if (!data.BeforeSendRequestCalled)
            {
                errorBuilder.AppendLine(String.Format("Did not call BeforeSendRequest"));
            }

            if (data.Request == null)
            {
                errorBuilder.AppendLine(String.Format("Did not call pass Request to BeforeSendRequest"));
            }

            if (data.Channel == null)
            {
                errorBuilder.AppendLine(String.Format("Did not call pass Channel to BeforeSendRequest"));
            }

            if (!data.AfterReceiveReplyCalled)
            {
                errorBuilder.AppendLine(String.Format("Did not call AfterReceiveReplyCalled"));
            }

            if (data.Reply == null)
            {
                errorBuilder.AppendLine(String.Format("Did not call pass Reply to AfterReceiveReplyCalled"));
            }
        }
        catch (Exception ex)
        {
            errorBuilder.AppendLine(String.Format("Unexpected exception was caught: {0}", ex.ToString()));
        }

        Assert.True(errorBuilder.Length == 0, string.Format("Test Scenario: ClientMessageInspectorScenario FAILED with the following errors: {0}", errorBuilder));
    }
Ejemplo n.º 12
0
    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.
        StringBuilder errorBuilder = new StringBuilder();
        try
        {
            CustomBinding customBinding = new CustomBinding();
            customBinding.Elements.Add(new TextMessageEncodingBindingElement());
            customBinding.Elements.Add(new HttpTransportBindingElement());

            MyClientBase client = new MyClientBase(customBinding, new EndpointAddress(BaseAddress.HttpBaseAddress));

            // 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));
            IWcfServiceGenerated serviceProxy = client.ChannelFactory.CreateChannel();

            // This proxy call should invoke the client message inspector
            string result = serviceProxy.Echo("Hello");
            if (!string.Equals(result, "Hello"))
            {
                errorBuilder.AppendLine(String.Format("Expected response from Service: {0} Actual was: {1}", "Hello", result));
            }

            if (!data.BeforeSendRequestCalled)
            {
                errorBuilder.AppendLine(String.Format("Did not call BeforeSendRequest"));
            }

            if (data.Request == null)
            {
                errorBuilder.AppendLine(String.Format("Did not call pass Request to BeforeSendRequest"));
            }

            if (data.Channel == null)
            {
                errorBuilder.AppendLine(String.Format("Did not call pass Channel to BeforeSendRequest"));
            }

            if (!data.AfterReceiveReplyCalled)
            {
                errorBuilder.AppendLine(String.Format("Did not call AfterReceiveReplyCalled"));
            }

            if (data.Reply == null)
            {
                errorBuilder.AppendLine(String.Format("Did not call pass Reply to AfterReceiveReplyCalled"));
            }
        }
        catch (Exception ex)
        {
            errorBuilder.AppendLine(String.Format("Unexpected exception was caught: {0}", ex.ToString()));
        }

        Assert.True(errorBuilder.Length == 0, string.Format("Test Scenario: ClientMessageInspectorScenario FAILED with the following errors: {0}", errorBuilder));
    }
Ejemplo n.º 13
0
    public static void OperationContextScope_HttpRequestCustomMessageHeader_RoundTrip_Verify()
    {
        string customHeaderName  = "OperationContextScopeCustomHeader";
        string customHeaderNS    = "http://tempuri.org/OperationContextScope_HttpRequestCustomMessageHeader_RoundTrip_Verify";
        string customHeaderValue = "CustomHappyValue";

        MyClientBase <IWcfService> client = null;
        IWcfService serviceProxy          = null;

        try
        {
            // *** SETUP *** \\
            BasicHttpBinding binding = new BasicHttpBinding();

            client       = new MyClientBase <IWcfService>(binding, new EndpointAddress(Endpoints.HttpBaseAddress_Basic));
            serviceProxy = client.ChannelFactory.CreateChannel();

            using (OperationContextScope scope = new OperationContextScope((IContextChannel)serviceProxy))
            {
                MessageHeader header
                    = MessageHeader.CreateHeader(
                          customHeaderName,
                          customHeaderNS,
                          customHeaderValue
                          );
                OperationContext.Current.OutgoingMessageHeaders.Add(header);

                // *** EXECUTE *** \\
                Dictionary <string, string> incomingMessageHeaders = serviceProxy.GetIncomingMessageHeaders();
                string result = ClientBaseTestHelpers.GetHeader(customHeaderName, customHeaderNS, incomingMessageHeaders);

                // *** VALIDATE *** \\
                Assert.Equal(customHeaderValue, result);
            }

            // *** EXECUTE *** \\
            //Call outside of scope should not have the custom header
            Dictionary <string, string> outofScopeIncomingMessageHeaders = serviceProxy.GetIncomingMessageHeaders();
            string outofScopeResult = ClientBaseTestHelpers.GetHeader(customHeaderName, customHeaderNS, outofScopeIncomingMessageHeaders);

            // *** VALIDATE *** \\
            Assert.True(string.Empty == outofScopeResult, string.Format("Expect call out of the OperationContextScope does not have the custom header {0}", customHeaderName));

            // *** CLEANUP *** \\
            ((ICommunicationObject)client).Close();
            ((ICommunicationObject)serviceProxy).Close();
        }
        finally
        {
            // *** ENSURE CLEANUP *** \\
            ScenarioTestHelpers.CloseCommunicationObjects((ICommunicationObject)serviceProxy, (ICommunicationObject)client);
        }
    }
Ejemplo n.º 14
0
    public static void ClientBaseCloseMethodClosesCorrectly()
    {
        // *** SETUP *** \\
        BasicHttpBinding binding = new BasicHttpBinding();
        MyClientBase     client  = new MyClientBase(binding, new EndpointAddress("http://myendpoint"));

        // *** VALIDATE *** \\
        Assert.Equal(CommunicationState.Created, client.State);
        client.Open();
        Assert.Equal(CommunicationState.Opened, client.State);
        client.Close();
        Assert.Equal(CommunicationState.Closed, client.State);
    }
Ejemplo n.º 15
0
    public static void ClientBaseOfT_Async_Open_Close_Events_Fire()
    {
        MyClientBase         client            = null;
        List <string>        eventsCalled      = new List <string>(4);
        List <string>        proxyEventsCalled = new List <string>(4);
        IWcfServiceGenerated proxy             = 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));

            // Listen to all events on the ClientBase and on the generated proxy
            ClientBaseTestHelpers.RegisterForEvents(client, eventsCalled);

            proxy = client.Proxy;
            ClientBaseTestHelpers.RegisterForEvents((ICommunicationObject)proxy, proxyEventsCalled);

            // *** EXECUTE *** \\
            Task <string> task = proxy.EchoAsync("Hello");
            task.GetAwaiter().GetResult();

            IAsyncResult ar = ((ICommunicationObject)client).BeginClose(null, null);
            ((ICommunicationObject)client).EndClose(ar);

            // *** VALIDATE *** \\

            // We expect both the ClientBase and the generated proxy to have fired all the open/close events
            string expected = "Opening,Opened,Closing,Closed";
            string actual   = String.Join(",", eventsCalled);

            Assert.True(String.Equals(expected, actual),
                        String.Format("Expected client to receive events '{0}' but actual was '{1}'", expected, actual));

            actual = String.Join(",", proxyEventsCalled);
            Assert.True(String.Equals(expected, actual),
                        String.Format("Expected proxy to receive events '{0}' but actual was '{1}'", expected, actual));

            // *** CLEANUP *** \\
        }
        finally
        {
            // *** ENSURE CLEANUP *** \\
            ScenarioTestHelpers.CloseCommunicationObjects((ICommunicationObject)proxy, (ICommunicationObject)client);
        }
    }
Ejemplo n.º 16
0
    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));
    }
Ejemplo n.º 17
0
    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));
    }
Ejemplo n.º 18
0
    public static void ClientBaseOfT_Dispose_Closes_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 *** \\
            // ClientBase is IDisposable, which should close the client, factory and proxy
            ((IDisposable)client).Dispose();

            // *** 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);
        }
    }
Ejemplo n.º 19
0
    public static void ClientBaseOfT_Sync_Removed_Open_Close_Events_Do_Not_Fire()
    {
        MyClientBase         client            = null;
        List <string>        eventsCalled      = new List <string>(4);
        List <string>        proxyEventsCalled = new List <string>(4);
        IWcfServiceGenerated proxy             = 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));

            // Both Add and Remove event handlers
            ClientBaseTestHelpers.RegisterForEvents(client, eventsCalled, deregister: true);

            proxy = client.Proxy;
            ClientBaseTestHelpers.RegisterForEvents((ICommunicationObject)proxy, proxyEventsCalled, deregister: true);

            // *** EXECUTE *** \\
            proxy.Echo("Hello");
            ((ICommunicationObject)client).Close();

            // *** VALIDATE *** \\

            // We expect both the ClientBase and the generated proxy to have NOT fired all the open/close events
            string actual = String.Join(",", eventsCalled);

            Assert.True(eventsCalled.Count == 0,
                        String.Format("Expected client NOT to receive events but actual was '{0}'", actual));

            actual = String.Join(",", proxyEventsCalled);
            Assert.True(proxyEventsCalled.Count == 0,
                        String.Format("Expected proxy NOT to receive events but actual was '{0}'", actual));

            // *** CLEANUP *** \\
        }
        finally
        {
            // *** ENSURE CLEANUP *** \\
            ScenarioTestHelpers.CloseCommunicationObjects((ICommunicationObject)proxy, (ICommunicationObject)client);
        }
    }
Ejemplo n.º 20
0
    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.

        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.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));

            serviceProxy = client.ChannelFactory.CreateChannel();

            // *** EXECUTE *** \\
            // This proxy call should invoke the client message inspector
            string result = serviceProxy.Echo("Hello");

            // *** VALIDATE *** \\
            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");

            // *** CLEANUP *** \\
            ((ICommunicationObject)client).Close();
            ((ICommunicationObject)serviceProxy).Close();
        }
        finally
        {
            // *** ENSURE CLEANUP *** \\
            ScenarioTestHelpers.CloseCommunicationObjects((ICommunicationObject)serviceProxy, (ICommunicationObject)client);
        }
    }
Ejemplo n.º 21
0
    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.

        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.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));

            serviceProxy = client.ChannelFactory.CreateChannel();

            // *** EXECUTE *** \\
            // This proxy call should invoke the client message inspector
            string result = serviceProxy.Echo("Hello");

            // *** VALIDATE *** \\
            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");

            // *** CLEANUP *** \\
            ((ICommunicationObject)client).Close();
            ((ICommunicationObject)serviceProxy).Close();
        }
        finally
        {
            // *** ENSURE CLEANUP *** \\
            ScenarioTestHelpers.CloseCommunicationObjects((ICommunicationObject)serviceProxy, (ICommunicationObject)client);
        }
    }
Ejemplo n.º 22
0
    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);
        }
    }
Ejemplo n.º 23
0
    public static void ClientBaseChannelFactoryDefaultCachingBindingEndpointAddress()
    {
        Assert.Equal(CacheSetting.Default, MyClientBase.CacheSetting);
        BasicHttpBinding binding         = new BasicHttpBinding();
        EndpointAddress  endpointAddress = new EndpointAddress("http://myendpoint");
        MyClientBase     client1         = new MyClientBase(binding, endpointAddress);

        client1.Open();
        MyClientBase client2 = new MyClientBase(binding, endpointAddress);

        client2.Open();
        Assert.NotEqual(client1.ChannelFactory, client2.ChannelFactory);
        client1.Close();
        client2.Close();
        // Validate setting to same value doesn't throw
        MyClientBase.CacheSetting = CacheSetting.Default;
        // Validate instantiated caching throws when changing setting
        Assert.Throws <InvalidOperationException>(() => MyClientBase.CacheSetting = CacheSetting.AlwaysOn);
    }
Ejemplo n.º 24
0
    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();
            }
        }
    }
Ejemplo n.º 25
0
    public static void OperationContextScope_HttpRequestCustomMessageHeader_RoundTrip_Verify()
    {
        // *** SETUP *** \\
        BasicHttpBinding binding = new BasicHttpBinding();
        MyClientBase <IWcfServiceXml_OperationContext> client = new MyClientBase <IWcfServiceXml_OperationContext>(binding, new EndpointAddress(Endpoints.HttpBaseAddress_Basic_Text));
        IWcfServiceXml_OperationContext serviceProxy          = client.ChannelFactory.CreateChannel();

        string customHeaderName  = "TestSessionHeader";
        string customHeaderNS    = "xmlns=urn:TestWebServices/MyWebService/";
        var    customHeaderValue = new MesssageHeaderCreateHeaderWithXmlSerializerTestType {
            Message = "secret"
        };

        try
        {
            using (OperationContextScope scope = new OperationContextScope((IContextChannel)serviceProxy))
            {
                // *** EXECUTE *** \\
                MessageHeader header
                    = MessageHeader.CreateHeader(
                          customHeaderName,
                          customHeaderNS,
                          customHeaderValue
                          );
                OperationContext.Current.OutgoingMessageHeaders.Add(header);

                string result = serviceProxy.GetIncomingMessageHeadersMessage(customHeaderName, customHeaderNS);

                // *** VALIDATE *** \\
                Assert.Equal(customHeaderValue.Message, result);
            }

            // *** CLEANUP *** \\
            ((ICommunicationObject)serviceProxy).Close();
        }
        finally
        {
            // *** ENSURE CLEANUP *** \\
            ScenarioTestHelpers.CloseCommunicationObjects((ICommunicationObject)serviceProxy, client);
        }
    }
Ejemplo n.º 26
0
    public static void OperationContextScope_HttpRequestCustomMessageHeader_RoundTrip_Verify()
    {
        // *** SETUP *** \\
        BasicHttpBinding binding = new BasicHttpBinding();
        MyClientBase<IWcfServiceXml_OperationContext> client = new MyClientBase<IWcfServiceXml_OperationContext>(binding, new EndpointAddress(Endpoints.HttpBaseAddress_Basic));
        IWcfServiceXml_OperationContext serviceProxy = client.ChannelFactory.CreateChannel();

        string customHeaderName = "TestSessionHeader";
        string customHeaderNS = "xmlns=urn:TestWebServices/MyWebService/";
        var customHeaderValue = new MesssageHeaderCreateHeaderWithXmlSerializerTestType { Message = "secret" };

        try
        {
            using (OperationContextScope scope = new OperationContextScope((IContextChannel)serviceProxy))
            {
                // *** EXECUTE *** \\
                MessageHeader header
                  = MessageHeader.CreateHeader(
                  customHeaderName,
                  customHeaderNS,
                  customHeaderValue
                  );
                OperationContext.Current.OutgoingMessageHeaders.Add(header);

                string result = serviceProxy.GetIncomingMessageHeadersMessage(customHeaderName, customHeaderNS);

                // *** VALIDATE *** \\
                Assert.Equal(customHeaderValue.Message, result);
            }

            // *** CLEANUP *** \\
            ((ICommunicationObject)serviceProxy).Close();
        }
        finally
        {
            // *** ENSURE CLEANUP *** \\
            ScenarioTestHelpers.CloseCommunicationObjects((ICommunicationObject)serviceProxy, client);
        }
    }
Ejemplo n.º 27
0
    public static void MessageProperty_HttpRequestMessageProperty_RoundTrip_Verify()
    {
        MyClientBase<IWcfService> client = null;
        IWcfService serviceProxy = null;

        try
        {
            // *** SETUP *** \\
            CustomBinding customBinding = new CustomBinding();
            customBinding.Elements.Add(new TextMessageEncodingBindingElement());
            customBinding.Elements.Add(new HttpTransportBindingElement());

            client = new MyClientBase<IWcfService>(customBinding, new EndpointAddress(Endpoints.DefaultCustomHttp_Address));
            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);
        }
    }
Ejemplo n.º 28
0
    public static void TestAccessFaultContractInfo()
    {
        MyClientBase<IWcfService> client = null;
        IWcfService serviceProxy = null;
        string action = @"http://tempuri.org/IWcfService/TestFaultFaultDetailFault";
        Type detail = typeof(FaultDetail);

        try
        {
            // *** SETUP *** \\
            CustomBinding customBinding = new CustomBinding();
            customBinding.Elements.Add(new TextMessageEncodingBindingElement());
            customBinding.Elements.Add(new HttpTransportBindingElement());

            client = new MyClientBase<IWcfService>(customBinding, new EndpointAddress(Endpoints.DefaultCustomHttp_Address));
            client.Endpoint.EndpointBehaviors.Add(new TestFaultContractInfosBehavior());
            serviceProxy = client.ChannelFactory.CreateChannel();

            // *** EXECUTE *** \\
            var input = new object[] { new FaultDetail(), new KnownTypeA() };
            // Use exiting service as we only need to verify FaultContractInfo can be accessed from ClientOperation
            serviceProxy.TestFaultWithKnownType(null, input);

            //Verify
            Assert.True(TestFaultContractInfosBehavior.testFaultWithKnownTypeClientOp != null, "Expected testFaultWithKnownTypeClientOp is NOT null");
            Assert.True(TestFaultContractInfosBehavior.testFaultWithKnownTypeClientOp.FaultContractInfos.Count == 1, string.Format("expected FaultContractInfos count is 1, actual: {0}", TestFaultContractInfosBehavior.testFaultWithKnownTypeClientOp.FaultContractInfos.Count));
            Assert.True(TestFaultContractInfosBehavior.testFaultWithKnownTypeClientOp.FaultContractInfos[0].Action == action, string.Format("expected FaultContractInfo Action is {0}, actual: {1}", action, TestFaultContractInfosBehavior.testFaultWithKnownTypeClientOp.FaultContractInfos[0].Action));
            Assert.True(TestFaultContractInfosBehavior.testFaultWithKnownTypeClientOp.FaultContractInfos[0].Detail == detail, string.Format("expected FaultContractInfo Detail is {0}, actual: {1}", detail.ToString(), TestFaultContractInfosBehavior.testFaultWithKnownTypeClientOp.FaultContractInfos[0].Detail.ToString()));

        }
        finally
        {
            // *** ENSURE CLEANUP *** \\
            ScenarioTestHelpers.CloseCommunicationObjects((ICommunicationObject)serviceProxy, (ICommunicationObject)client);
        }
    }
Ejemplo n.º 29
0
    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();
            }
        }
    }
Ejemplo n.º 30
0
    public static void ClientBaseOfT_Async_Open_Close_TimeSpan_Factory_And_Proxy_CommunicationState()
    {
        MyClientBase         client                   = null;
        IWcfServiceGenerated serviceProxy             = null;
        ChannelFactory <IWcfServiceGenerated> factory = null;
        TimeSpan timeout = ScenarioTestHelpers.TestTimeout;

        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;

            // *** VALIDATE *** \\
            Assert.True(CommunicationState.Created == client.State,
                        String.Format("Expected client state to be Created but actual was '{0}'", client.State));

            Assert.True(CommunicationState.Created == factory.State,
                        String.Format("Expected channel factory state to be Created but actual was '{0}'", factory.State));

            // Note: both the full framework and this NET Core version open the channel factory
            // when asking for the internal channel.  Attempting to Open the ClientBase
            // after obtaining the internal channel with throw InvalidOperationException attempting
            // to reopen the channel factory.  Customers don't encounter this situation in normal use
            // because access to the internal channel is protected and cannot be acquired.  So we
            // defer asking for the internal channel in this test to allow the Open() to follow the
            // same code path as customer code.

            // *** EXECUTE *** \\
            // Explicitly async open the ClientBase to follow general WCF guidelines
            IAsyncResult ar = ((ICommunicationObject)client).BeginOpen(timeout, null, null);
            ((ICommunicationObject)client).EndOpen(ar);

            // Use the internal proxy generated by ClientBase to most resemble how svcutil-generated code works.
            // This test defers asking for it until the ClientBase is open to avoid the issue described above.
            serviceProxy = client.Proxy;

            Assert.True(CommunicationState.Opened == client.State,
                        String.Format("Expected client state to be Opened but actual was '{0}'", client.State));

            Assert.True(CommunicationState.Opened == factory.State,
                        String.Format("Expected channel factory state to be Opened but actual was '{0}'", factory.State));

            Assert.True(CommunicationState.Opened == ((ICommunicationObject)serviceProxy).State,
                        String.Format("Expected proxy state to be Opened but actual was '{0}'", ((ICommunicationObject)serviceProxy).State));

            // *** EXECUTE *** \\
            // Explicitly close the ClientBase to follow general WCF guidelines
            ar = ((ICommunicationObject)client).BeginClose(timeout, null, null);
            ((ICommunicationObject)client).EndClose(ar);

            // *** 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);
        }
    }
Ejemplo n.º 31
0
    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();
            }
        }
    }
Ejemplo n.º 32
0
    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);
        }
    }
Ejemplo n.º 33
0
    public static void OperationContextScope_HttpRequestCustomMessageHeader_RoundTrip_Verify()
    {
        string customHeaderName = "OperationContextScopeCustomHeader";
        string customHeaderNS = "http://tempuri.org/OperationContextScope_HttpRequestCustomMessageHeader_RoundTrip_Verify";
        string customHeaderValue = "CustomHappyValue";

        MyClientBase<IWcfService> client = null;
        IWcfService serviceProxy = null;

        try
        {
            // *** SETUP *** \\
            BasicHttpBinding binding = new BasicHttpBinding();

            client = new MyClientBase<IWcfService>(binding, new EndpointAddress(Endpoints.HttpBaseAddress_Basic));
            serviceProxy = client.ChannelFactory.CreateChannel();

            using (OperationContextScope scope = new OperationContextScope((IContextChannel)serviceProxy))
            {
                MessageHeader header
                  = MessageHeader.CreateHeader(
                  customHeaderName,
                  customHeaderNS,
                  customHeaderValue
                  );
                OperationContext.Current.OutgoingMessageHeaders.Add(header);

                // *** EXECUTE *** \\
                Dictionary<string, string> incomingMessageHeaders = serviceProxy.GetIncomingMessageHeaders();
                string result = GetHeader(customHeaderName, customHeaderNS, incomingMessageHeaders);

                // *** VALIDATE *** \\
                Assert.Equal(customHeaderValue, result);
            }

            // *** EXECUTE *** \\
            //Call outside of scope should not have the custom header
            Dictionary<string, string> outofScopeIncomingMessageHeaders = serviceProxy.GetIncomingMessageHeaders();
            string outofScopeResult = GetHeader(customHeaderName, customHeaderNS, outofScopeIncomingMessageHeaders);

            // *** VALIDATE *** \\
            Assert.True(string.Empty == outofScopeResult, string.Format("Expect call out of the OperationContextScope does not have the custom header {0}", customHeaderName));

            // *** CLEANUP *** \\
            ((ICommunicationObject)client).Close();
            ((ICommunicationObject)serviceProxy).Close();
        }
        finally
        {
            // *** ENSURE CLEANUP *** \\
            ScenarioTestHelpers.CloseCommunicationObjects((ICommunicationObject)serviceProxy, (ICommunicationObject)client);
        }
    }
Ejemplo n.º 34
0
    public static void ClientBaseOfT_Call()
    {
        // This test verifies ClientBase<T> can be used to create a proxy and invoke an operation
        StringBuilder errorBuilder = new StringBuilder();
        try
        {
            CustomBinding customBinding = new CustomBinding();
            customBinding.Elements.Add(new TextMessageEncodingBindingElement());
            customBinding.Elements.Add(new HttpTransportBindingElement());

            MyClientBase client = new MyClientBase(customBinding, new EndpointAddress(BaseAddress.HttpBaseAddress));
            IWcfServiceGenerated serviceProxy = client.ChannelFactory.CreateChannel();

            string result = serviceProxy.Echo("Hello");
            if (!string.Equals(result, "Hello"))
            {
                errorBuilder.AppendLine(String.Format("Expected response from Service: {0} Actual was: {1}", "Hello", result));
            }
        }
        catch (Exception ex)
        {
            errorBuilder.AppendLine(String.Format("Unexpected exception was caught: {0}", ex.ToString()));
        }

        Assert.True(errorBuilder.Length == 0, string.Format("Test Scenario: ClientBaseOfTCall FAILED with the following errors: {0}", errorBuilder));
    }
Ejemplo n.º 35
0
    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) 

        MyClientBase client = null;
        IWcfServiceGenerated serviceProxy = null;

        try
        {
            // *** SETUP *** \\
            CustomBinding binding = new CustomBinding(new TextMessageEncodingBindingElement(), new TcpTransportBindingElement());

            client = new MyClientBase(binding, new EndpointAddress(Endpoints.Tcp_CustomBinding_NoSecurity_Text_Address));
            serviceProxy = client.ChannelFactory.CreateChannel();

            // *** EXECUTE *** \\
            string result = serviceProxy.Echo("Hello");

            // *** VALIDATE *** \\
            Assert.Equal("Hello", result);

            // *** CLEANUP *** \\
            ((ICommunicationObject)client).Close();
            ((ICommunicationObject)serviceProxy).Close();
        }
        finally
        {
            // *** ENSURE CLEANUP *** \\
            ScenarioTestHelpers.CloseCommunicationObjects((ICommunicationObject)serviceProxy, (ICommunicationObject)client);
        }
    }