In last post , we have seen how to add WCF reference in .Net Core Application. In this example we will see how we can call different WCF operations or methods both with Http link and Https link.
If the target WCF link is Http link then you can create the WCF client instance using following code snippet:
BasicHttpBinding basicHttpBinding = new BasicHttpBinding(); EndpointAddress endpointAddress = new EndpointAddress("https://localhost:8081/OrderManagement/OrderManagement.svc"); OrderManagementClient wcfClient = new OrderManagementClient(basicHttpBinding, endpointAddress); var result = wcfClient.GetOrderByID(1);
However if the WCF link is bound over Https, then you have to make small changes in order to consume service with Https. You have to by-pass SSL Certificate Authentication. You can use following code snippet to consume WCF Service with Https link:
BasicHttpBinding basicHttpBinding = new BasicHttpBinding(); EndpointAddress endpointAddress = new EndpointAddress("https://localhost:8082/OrderManagement/OrderManagement.svc"); OrderManagementClient wcfClient = new OrderManagementClient(basicHttpBinding, endpointAddress); //wcfClient.ClientCredentials.ServiceCertificate.SslCertificateAuthentication //is need to be set for Https certificate authentication wcfClient.ClientCredentials.ServiceCertificate.SslCertificateAuthentication = new X509ServiceCertificateAuthentication() { CertificateValidationMode = X509CertificateValidationMode.None, RevocationMode = System.Security.Cryptography.X509Certificates.X509RevocationMode.NoCheck }; var result = wcfClient.GetOrderByID(1);
No comments:
Post a Comment