开发者

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&开发者_运维百科lt;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


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜