Click here to Skip to main content
15,890,512 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Our vendor gave us webservices developed using java with message encrypted(WSS),and we have three certificates as below
1) Client Certifcate(our private key and public key)
2) Server Certificate (vendor public key)
3) 2 way ssl certificate

can somebody help me to consume the java web service in our .net client?

specifically I am not sure how to add these 3 certificates in .net client

What I have tried:

I have tried with .net cosole application to consume but not sure where to add the 2way ssl certificate.

I have tried with these code:

var b = new CustomBinding();

           var sec = (AsymmetricSecurityBindingElement)SecurityBindingElement.CreateMutualCertificateBindingElement(MessageSecurityVersion.WSSecurity10WSTrust13WSSecureConversation13WSSecurityPolicy12BasicSecurityProfile10);
           sec.MessageSecurityVersion =  MessageSecurityVersion.WSSecurity10WSTrust13WSSecureConversation13WSSecurityPolicy12BasicSecurityProfile10;
           sec.IncludeTimestamp = true;
           sec.MessageProtectionOrder = System.ServiceModel.Security.MessageProtectionOrder.SignBeforeEncrypt;

           b.Elements.Add(sec);
           b.Elements.Add(new TextMessageEncodingBindingElement(MessageVersion.Soap11, Encoding.UTF8));
           b.Elements.Add(new HttpsTransportBindingElement());

           var c = new serRef.VendorServicePortTypeClient(b,
               new EndpointAddress(new Uri("end point url"),
               new DnsEndpointIdentity("identiyname"), new AddressHeaderCollection()));


           //here attached our certificate
           c.ClientCredentials.ClientCertificate.SetCertificate(System.Security.Cryptography.X509Certificates.StoreLocation.LocalMachine,
                                              System.Security.Cryptography.X509Certificates.StoreName.My, System.Security.Cryptography.X509Certificates.X509FindType.FindBySerialNumber, "xxxxxxxxxxxx");


           ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3;


           c.ClientCredentials.ServiceCertificate.Authentication.CertificateValidationMode = System.ServiceModel.Security.X509CertificateValidationMode.None;

           //here attached vendor certificate
           c.ClientCredentials.ServiceCertificate.DefaultCertificate = new X509Certificate2(@"ServerPublicKey.cer");
           c.Endpoint.Contract.ProtectionLevel = System.Net.Security.ProtectionLevel.Sign;

           string a = "";
           string a2 = "";

           var x= c.Ping(out a,out a2);
Posted
Updated 21-Dec-20 10:03am

1 solution

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900