Пример #1
0
    public static void Echo_With_CustomClientMessageFormatter_RoundTrips_String()
    {
        ChannelFactory <IWcfService> factory = null;
        IWcfService serviceProxy             = null;
        string      testString = "Hello";
        Binding     binding    = null;

        try
        {
            // *** SETUP *** \\
            binding = new BasicHttpBinding(BasicHttpSecurityMode.None);
            factory = new ChannelFactory <IWcfService>(binding, new EndpointAddress(Endpoints.HttpBaseAddress_Basic_Text));

            string suffix         = "_suffix";
            var    customBehavior = new AppendSuffixToStringBehavior(suffix);

            // Apply the custom behavior to each operation of the contract.
            foreach (OperationDescription operation in factory.Endpoint.Contract.Operations)
            {
                operation.OperationBehaviors.Add(customBehavior);
            }

            // AppendSuffixToStringBehavior appends the suffix to each string parameter
            // when creating request message, so we expect the server would echo testString + suffix
            string expectedResult = testString + suffix;

            serviceProxy = factory.CreateChannel();

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

            // *** VALIDATE *** \\
            Assert.True(result == expectedResult, string.Format("Error: expected response from service: '{0}' Actual was: '{1}'", expectedResult, result));

            // *** CLEANUP *** \\
            factory.Close();
            ((ICommunicationObject)serviceProxy).Close();
        }
        finally
        {
            // *** ENSURE CLEANUP *** \\
            ScenarioTestHelpers.CloseCommunicationObjects((ICommunicationObject)serviceProxy, factory);
        }
    }
Пример #2
0
    public static void Echo_With_CustomClientMessageFormatter_RoundTrips_String()
    {
        ChannelFactory<IWcfService> factory = null;
        IWcfService serviceProxy = null;
        string testString = "Hello";
        Binding binding = null;

        try
        {
            // *** SETUP *** \\
            binding = new BasicHttpBinding(BasicHttpSecurityMode.None);
            factory = new ChannelFactory<IWcfService>(binding, new EndpointAddress(Endpoints.HttpBaseAddress_Basic));

            string suffix = "_suffix";
            var customBehavior = new AppendSuffixToStringBehavior(suffix);

            // Apply the custom behavior to each operation of the contract.
            foreach (OperationDescription operation in factory.Endpoint.Contract.Operations)
            {
                operation.OperationBehaviors.Add(customBehavior);
            }

            // AppendSuffixToStringBehavior appends the suffix to each string parameter
            // when creating request message, so we expect the server would echo testString + suffix
            string expectedResult = testString + suffix;

            serviceProxy = factory.CreateChannel();

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

            // *** VALIDATE *** \\
            Assert.True(result == expectedResult, string.Format("Error: expected response from service: '{0}' Actual was: '{1}'", expectedResult, result));

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