Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to connect Java client to WCF service using clientCredentialType="Basic"

I have to connect from a Java client to a WCF Web Service which has the following binding configuration:

<basicHttpBinding>
    <binding name="basicHttpBindingSecurity">
        <security mode="TransportCredentialOnly">
            <transport clientCredentialType="Basic"/>
        </security>
    </binding>
</basicHttpBinding>

I'm using JAX-WS. Can you give me a code snippet showing how to set user name and password in a Java client?

I have tried this:

Map<String, Object> reqContext = ((BindingProvider) port).getRequestContext();
reqContext.put(BindingProvider.USERNAME_PROPERTY, "username");
reqContext.put(BindingProvider.PASSWORD_PROPERTY, "password");

but it did not work. I have also tried this:

Map<String, Object> reqContext = ((BindingProvider) port).getRequestContext();
reqContext.put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, "http://username:password@localhost:8090/MyService");

Still no success.

Thanks, Rafal

like image 796
Rafal Avatar asked Nov 06 '22 17:11

Rafal


1 Answers

Oops! Sorry...

First solution works, but I have made a mistake in WCF service configuration. So basicaly if you have similar problem tired this:

Map<String, Object> reqContext = ((BindingProvider) port).getRequestContext();
reqContext.put(BindingProvider.USERNAME_PROPERTY, "username");
reqContext.put(BindingProvider.PASSWORD_PROPERTY, "password");

Best regards, Rafal

like image 137
Rafal Avatar answered Nov 12 '22 15:11

Rafal