Mismatch in SOAP Request Namespace Prefix and Structure Using Spring Boot and JAXB

I’m working on a Spring Boot project where I need to consume a SOAP web service. I used wsdl2java to generate the client code. However, I’m encountering issues with the generated SOAP request message structure.

Here is the expected SOAP request from SOAP-UI:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:uri="http://uri.org/">
   <soapenv:Header/>
   <soapenv:Body>
      <uri:GetPolicy>
         <uri:policyId>12345</uri:policyId>
      </uri:GetPolicy>
   </soapenv:Body>
</soapenv:Envelope>

However, my Spring Boot application generates the following SOAP request:

<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
    <SOAP-ENV:Header/>
    <SOAP-ENV:Body>
        <ns3:GetPolicy xmlns:ns2="http://schemas.datacontract.org/2004/07/WcfPolicyServicesLibrary" xmlns:ns3="http://uri.org/" xmlns:ns4="http://schemas.microsoft.com/2003/10/Serialization/Arrays" xmlns:ns5="http://schemas.microsoft.com/2003/10/Serialization/">
            <ns3:policyId>12345</ns3:policyId>
        </ns3:GetPolicy>
    </SOAP-ENV:Body>
</SOAP-ENV:Envelope>

The differences include are as follows, when I am trying I am getting an error because of the incorrect request SOAP payload.

  1. Namespace prefixes (soapenv vs SOAP-ENV).
  2. Additional unnecessary namespaces.

Here’s my GetPolicy class:

@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "", propOrder = {
    "policyId"
})
@XmlRootElement(name = "GetPolicy")
public class GetPolicy {

    @XmlElementRef(name = "policyId", namespace = "http://uri.org/", type = JAXBElement.class, required = false)
    protected JAXBElement<String> policyId;

    public JAXBElement<String> getPolicyId() {
        return policyId;
    }

    public void setPolicyId(JAXBElement<String> value) {
        this.policyId = value;
    }
}

And here is the configuration and code where I execute the request:

@Autowired
private WebServiceTemplate webServiceTemplate;

ObjectFactory factory = new ObjectFactory();
GetPolicy request = factory.createGetPolicy();
request.setPolicyId(factory.createGetPolicyPolicyId("12345"));

webServiceTemplate.setMarshaller(jaxb2Marshaller);
webServiceTemplate.setUnmarshaller(jaxb2Marshaller);
webServiceTemplate.setDefaultUri("SOAP_SERVER_URL");

JAXBElement<GetPolicyResponse> response = (JAXBElement<GetPolicyResponse>) webServiceTemplate.marshalSendAndReceive(request, new SoapActionCallback("SOAP_ACTION"));
return response.getValue();

I have also ensured the correct package-level namespace definition in package-info.java:

@jakarta.xml.bind.annotation.XmlSchema(
    namespace = "http://uri.org/",
    elementFormDefault = jakarta.xml.bind.annotation.XmlNsForm.QUALIFIED
)
package my.package.name;

Despite these configurations, the generated SOAP request has the incorrect namespace prefixes and includes additional namespaces. Also, I know that by adding XmlNs I can fix the prefix issue, but I have multiple namespaceURI which should be matched to the same prefix. That’s where I stuck with.

Questions:

  1. How can I ensure the generated SOAP request uses soapenv as the namespace prefix instead of SOAP-ENV?
  2. How can I prevent the inclusion of unnecessary namespaces in the
    generated SOAP request?

Thank you. Any help would be greatly appreciated!

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật