我正在尝试创建一个独立的客户端来使用一些Web服务。我必须将我的用户名和密码添加到SOAP头中。我尝试按照以下方式添加凭据:
OTSWebSvcsService service = new OTSWebSvcsService();
OTSWebSvcs port = service.getOTSWebSvcs();
BindingProvider prov = (BindingProvider)port;
prov.getRequestContext().put(BindingProvider.USERNAME_PROPERTY, "myusername");
prov.getRequestContext().put(BindingProvider.PASSWORD_PROPERTY, "mypassword");
...
我在调用服务的方法时,遇到了以下异常:
com.ibm.wsspi.wssecurity.SoapSecurityException: WSEC5048E: One of "SOAP Header" elements required.
我做错了什么?我该如何将这些属性添加到SOAP头中?
编辑:我之前使用的是JDK6中包含的JAX-WS 2.1。我现在使用的是JAX-WS 2.2。我现在收到以下异常:
com.ibm.wsspi.wssecurity.SoapSecurityException: WSEC5509E: A security token whose type is [http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#UsernameToken] is required.
我该如何创建这个令牌?