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
精彩评论