Web Services 错误代码:验证消息的安全性时出错

t9eec4r0  于 2022-11-15  发布在  其他
关注(0)|答案(1)|浏览(158)

我正在使用以下CXF客户端调用SOAP Web服务:

QName serviceQName = new QName("Namespace", "ServiceName");
String urlString = "https:endpoint?wsdl";
QName portQName = new QName("Namespace", "PortName");

service = Service.create(serviceQName);
service.addPort(portQName, SOAPBinding.SOAP12HTTP_BINDING, urlString);
Dispatch<Source> sourceDispatch = service.createDispatch(portQName, Source.class, Service.Mode.PAYLOAD);
BindingProvider bindingProvider = sourceDispatch;
bindingProvider.getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, urlString);
bindingProvider.getRequestContext().put(TLSClientParameters.class.getName(), tlsParams);
Source result = sourceDispatch.invoke(new StreamSource(exchange.getIn().getBody(InputStream.class)));

我得到以下错误:

javax.xml.ws.soap.SOAPFaultException: An error occurred when verifying security for the message
dhxwm5r4

dhxwm5r41#

解决方案是添加一个SOAP操作和一些HTTP标头,如下所示:

bindingProvider.getRequestContext().put(BindingProvider.SOAPACTION_URI_PROPERTY, "myRequestAction");
Map<String, List<String>> requestHeaders = new HashMap<>();
requestHeaders.put("HeaderName", Arrays.asList("HeaderValue"));

相关问题