views:

160

answers:

2

Im trying to consume a Java web-service, that uses a certificate. I could generate the proxy, adding Service Reference. The problem is: It needs Basic HTTP Authorization Header. Its necessary to encript the user/password and pass them in the header.

Thanks.

A: 

It depends on the version of .NET you're using.

If you can use WCF, all you have to do is change the binding, pass the credentials, and let the Framework do the work.

You can find the instructions for configuration here (you only need the second half for Client configuration):

Transport Security with Basic Authentication - MSDN

Otherwise, you can download Web Service Extensions (WSE) 3.0 and use that for the simple authentication.

Implementing Direct Authentication with UsernameToken in WSE 3.0

Justin Niessner
Thanks for the WCF solution. Worked using the ServiceModel components, in the client (Windows Forms). For authorization, I just enabled the binding to use Basic security, and passed in the Client Credentials.
Erup
A: 

It sounds like the Java webservice is using SSL TLS protocol instead of the old school SSL protocol. You don't need to "encrypt the certificate username and password in the header". I don't now where you heard that. If its a regular certificate that is part of Java's default cacerts keystore then Java already has the password built into it.

In the case that i is a self signed cert (on the webservice end) you might need to somehow tell C# to trust self-signed cert. Also, the "credentials" that you are referring to are not the username + password, but is instead just the private key payload.

djangofan
I think you didnt get what I supposed to mean, but its ok. I mean that in the custom header, Its needed to pass the credentials. I already added the certificate into trusted certificates.
Erup
To force the app trust the certificate, I used the workaround described here: http://www.ben-morris.com/asp-net-web-services-and-ssl-certificates-establishing-a-trust-relationship
Erup