Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Invoking Java web service from C# client using JKS and/or PFX certificates

I basically need to secure my requests towards this service.

I've been provided a JAR test client and two files, trust.jks and Client.pfx, but I have no clue how to use them: I understand X509Certificate2 class is involved in some way.

The command line to execute the test client is the following:

java -Djavax.net.ssl.trustStore=trust.jks -Djavax.net.ssl.trustStorePassword=******** -Djavax.net.ssl.trustStoreType=JKS -Djavax.net.ssl.keyStore=Client.pfx -Djavax.net.ssl.keyStoreType=pkcs12 -Djavax.net.ssl.keyStorePassword=******** -jar TestClient.jar https://myServiceurl

It works, so I can both see the service, and the service itself should be properly configured.

My C# client (it's targeting .NET 2.0) uses a normal Web Reference to perform requests:

wsReferenceClient service = new wsReferenceClient();
//certificate code here ?
//maybe service.ClientCertificates.Add(<X509Certificate2 object built somehow>); ?
service.MyRequest(myParameters);

Server settings should be setup properly.

I fumbled around with the X509Certificate2 methods but I can't come out with something that makes sense, so the answer to the 'what have you tried?' question at the moment is 'I don't really know what to try in the first place'.

Any help would be really appreciated.

like image 365
Alex Avatar asked Apr 13 '12 09:04

Alex


People also ask

How do I invoke a web service?

You just need to provide the Web Service URL, select POST, set the proper content-type header (text/xml, application/soap+xml, etc.), and provide the proper xml soap body in the request. Click Send.

How do you call a SOAP service?

Right-click the SOAP element and select Consume SOAP Web Service....


1 Answers

Turns out I don't need to do anything with the JKS file.

wsReferenceClient service = new wsReferenceClient();
X509Certificate2 cert = new X509Certificate2();
cert.Import("Client.pfx", "<the password>", DefaultKeySet);
service.ClientCertificates.Add(cert);
service.MyRequest(myParameters);

This allows my HTTPS requests to go through successfully.

like image 170
Alex Avatar answered Nov 13 '22 19:11

Alex