我基于xmlbeans构建了wsdl-client-stub。现在我因使用xmlbeans添加自定义标头以进行身份验证而陷入困境,因为xmlbeans存根缺少必要的类(?)
实际上,标题应如下所示:
<SOAP-ENV:Header>
<ns2:verifyingToken>
<UserID>9</UserID>
<Token>29438094lkjslfkjlsdkjf</Token>
</ns2:verifyingToken>
</SOAP-ENV:Header>
所以我尝试在存根和ServiceClient之间进行后退:
ServiceClient sc = stub._getServiceClient();
OMFactory omFactory = OMAbstractFactory.getOMFactory();
OMElement omElement = omFactory.createOMElement(new QName("SOAP-ENV", "Header", "ver"), null);
OMElement omElementVeri = omFactory.createOMElement(new QName("", "verifyingToken", ""), omElement);
OMElement omElementUser = omFactory.createOMElement(new QName("", "UserID", ""), omElementVeri);
omElementUser.setText(""+userid);
OMElement omElementPass = omFactory.createOMElement(new QName("", "Token", ""), omElementVeri);
omElementPass.setText(""+token);
sc.addHeader(omElement);
eclipse正在提出错误说:
OMFactory类型中的方法createOMElement(String,OMNamespace)不适用于参数(QName,null)
- 构造函数QName(String,String,String)未定义
有没有人有一个提示,我应该修复,让这个工作。 我非常感谢你的帮助,
亚历
答案 0 :(得分:6)
ServiceClient client = stub._getServiceClient();
SOAP11Factory factory = new SOAP11Factory();
OMNamespace SecurityElementNamespace = factory.createOMNamespace("http://schemas.xmlsoap.org/ws/2002/12/secext", "wss");
OMElement usernameTokenEl = factory.createOMElement("UsernameToken", SecurityElementNamespace);
OMElement usernameEl = factory.createOMElement("Username", SecurityElementNamespace);
usernameEl.setText("123");
usernameTokenEl.addChild(usernameEl);
OMElement passwordEl = factory.createOMElement("Password", SecurityElementNamespace);
passwordEl.setText("123");
usernameTokenEl.addChild(passwordEl);
SOAPHeaderBlockImpl block = new SOAP11HeaderBlockImpl("Security", SecurityElementNamespace, factory);
block.addChild(usernameTokenEl);
client.addHeader(block);