JAX-WS 显式添加 SOAPAction 后发送空值 header

JAX-WS sending empty value after explicitly adding SOAPAction header

我已经使用现有 WSDL 文档中的 NetBeans 8.2 向导创建了 Web 服务客户端。 Java8 和 JAX-WS 使用 2.2.9。

据我所知,向导创建的代码都按预期工作,但查询缺少 "SOAPAction" header 中的值,这是查询工作所需的值。 header 键存在但值为空字符串:SOAPAction: "" 而它应该是 SOAPAction = "SendReports"

我试过用这个:

Map<String, List<String>> requestHeaders = new HashMap<>();
requestHeaders.put("SOAPAction", Arrays.asList("sendReports"));
sourceDispatch.getRequestContext().put(MessageContext.HTTP_REQUEST_HEADERS, requestHeaders);

-> 这也会导致空值。如果我输入 "SOAPAction_2" & "sendReports",那 header 是正确的,但显然 header 键是错误的,无法解决我的问题。之后有什么东西覆盖了我的价值?

webservice方法有注解:

@WebMethod(operationName = "SendReports", action = "SendReports")

关于我接下来可以尝试什么的任何提示?

我看到很多帖子建议使用 BindingProvider,但我无法使用 com.sun.* 包,原因不明。

终于找到了可行的解决方案。

我用 Netbeans 创建了一个 Web 服务 Dispatch 客户端(和原来一样)并且必须添加 SOAPACTION_USE_PROPERTY 和 SOAPACTION_URI_PROPERTY。 这些我以前曾尝试过作为系统属性,但似乎不能那样工作。

这是工作片段:

public void sendReports() throws IOException {
    ReportService service = new ReportService();
    QName portQName = new QName("http://URL/ReportService", "ReportService");
    req = readFile("C:/temp/myFile.xml", "UTF-8");;
    try {

        // Call Web Service Operation
        Dispatch<Source> sourceDispatch = null;
        sourceDispatch = service.createDispatch(portQName, Source.class, Service.Mode.PAYLOAD);

        Map<String, Object> map = sourceDispatch.getRequestContext();
        map.put(BindingProvider.SOAPACTION_USE_PROPERTY, Boolean.TRUE);
        map.put(BindingProvider.SOAPACTION_URI_PROPERTY, "SendReports");

        Source result = sourceDispatch.invoke(new StreamSource(new StringReader(req)));
    } catch (Exception ex) {
        // TODO handle custom exceptions here
    }
}