question

RizwanAnsari-9614 avatar image
0 Votes"
RizwanAnsari-9614 asked

Consume WSDL With Message Certificates .Net Core 5

Dear Experts,

Some service provider gave physical wsdl and certificates, also they provided sample in .net framework 4.7.
In .net framework the below code works

        var binding = new BasicHttpsBinding();
         binding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Certificate;
         var dns = new DnsEndpointIdentity(ConfigurationManager.AppSettings["DnsEndpointIdentity"]);
         var address = new EndpointAddress(new Uri(ConfigurationManager.AppSettings["EndpointAddress"]), dns, new AddressHeader[] { });
         binding.Security.Message.ClientCredentialType = BasicHttpMessageCredentialType.Certificate;
         var securityElement = SecurityBindingElement.CreateMutualCertificateBindingElement(MessageSecurityVersion.WSSecurity10WSTrustFebruary2005WSSecureConversationFebruary2005WSSecurityPolicy11BasicSecurityProfile10, true);
         securityElement.IncludeTimestamp = true;
         securityElement.MessageSecurityVersion = MessageSecurityVersion.WSSecurity11WSTrustFebruary2005WSSecureConversationFebruary2005WSSecurityPolicy11BasicSecurityProfile10;
         var customBinding = new CustomBinding(binding);
         customBinding.Elements.Insert(0, securityElement);
            
         Client proxy = new Client(customBinding, address);
         proxy.ChannelFactory.Endpoint.Contract.ProtectionLevel = System.Net.Security.ProtectionLevel.Sign;
         proxy.ClientCredentials.ClientCertificate.SetCertificate(StoreLocation.LocalMachine, StoreName.My, X509FindType.FindBySubjectName, ConfigurationManager.AppSettings["ClientCertificate"]);
         proxy.ClientCredentials.ServiceCertificate.Authentication.CertificateValidationMode = X509CertificateValidationMode.PeerOrChainTrust;
         proxy.ClientCredentials.ServiceCertificate.SetDefaultCertificate(StoreLocation.LocalMachine, StoreName.Root, X509FindType.FindBySubjectName, ConfigurationManager.AppSettings["ServiceCertificate"]);
         proxy.InnerChannel.OperationTimeout = new TimeSpan(0, 0, 3, 0);
         return proxy;

Same code not working in .net core 5, please help.

Regards

dotnet-aspnet-core-general
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

0 Answers