如何在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();

10-04 12:06