CXF:javax.xml.ws.soap.SOAPFaultException:验证消息的安全性时出错

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

我正在使用以下 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

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

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