java - 在 JAX-WS 中更改 SOAPRequest 前缀

标签 java web-services jax-ws soap-client

如何在 JAX-WS 中更改 SOAP 请求前缀。我更新了 handlemessage 中的 setprofix 方法

        SOAPMessage msgs = ctx.getMessage();

        SOAPMessage sm = MessageFactory.newInstance(SOAPConstants.SOAP_1_2_PROTOCOL).createMessage();
         sm.getSOAPPart().getEnvelope().setPrefix("soap");
         sm.getSOAPPart().getEnvelope().removeNamespaceDeclaration("env");
         sm.getSOAPHeader().setPrefix("soap");
         sm.getSOAPBody().setPrefix("soap");*/

但我仍然收到相同的请求

       <?xml version="1.0"?>
       <S:Envelope xmlns:xsd="http://www.w3.org/2001/XMLSchema"

我需要

      <Soap:Envelope xmlns:xsd="http://www.w3.org/2001/XMLSchema" 

请帮忙

最佳答案

    final SOAPMessage soapMsg = context.getMessage();
    soapMsg.getSOAPPart().getEnvelope().setAttributeNS("http://www.w3.org/2000/xmlns/", "xmlns:soap", "http://schemas.xmlsoap.org/soap/envelope/");
    soapMsg.getSOAPPart().getEnvelope().removeAttributeNS("http://schemas.xmlsoap.org/soap/envelope/", "env");
    soapMsg.getSOAPPart().getEnvelope().removeAttribute("xmlns:env");
    soapMsg.getSOAPPart().getEnvelope().setPrefix("soap");
    soapMsg.getSOAPBody().setPrefix("soap");
    soapMsg.getSOAPPart().getEnvelope().getHeader().detachNode();

关于java - 在 JAX-WS 中更改 SOAPRequest 前缀,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14967691/

相关文章:

python - 对作为网络服务运行的程序进行逆向工程, future ?

c# - 使用客户端 Web 服务时出现内容错误

c# - 使用 WCF Web 服务发送 1 个包含 100 万个整数的数组等于大超时?

java - JPA 实体解析错误

java - jaxws 网络服务。更改节点结构

java - 在Eclipse中使用Jsoup时出错

java - 使用带有可为空外键的 QueryDSL 在 Spring Data JPA Repository 中进行过滤

java - 如何使用 hibernate 删除/编辑 JTable 和 MySQL 中的行?

java - 强制调用所有方法

java - 通过 JAX-WS 使用 Web 服务