Exemple #1
0
    public static async Task ServerCertificateValidationUsingIdentity_EchoString()
    {
        EndpointAddress              endpointAddress    = null;
        X509Certificate2             serviceCertificate = null;
        string                       testString         = "Hello";
        ChannelFactory <IWcfService> factory            = null;
        IWcfService                  serviceProxy       = null;

        try
        {
            // *** SETUP *** \\
            CustomBinding binding = new CustomBinding(new TextMessageEncodingBindingElement(MessageVersion.Soap11, Encoding.UTF8), new HttpsTransportBindingElement());

            serviceCertificate = await ServiceUtilHelper.GetServiceMacineCertFromServerAsync();

            var identity = new X509CertificateEndpointIdentity(serviceCertificate);
            endpointAddress = new EndpointAddress(new Uri(Endpoints.Https_DefaultBinding_Address_Text), identity);

            factory      = new ChannelFactory <IWcfService>(binding, endpointAddress);
            serviceProxy = factory.CreateChannel();

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

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

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