【问题标题】:Get rid of empty xmlns element in JAX-WS摆脱 JAX-WS 中的空 xmlns 元素
【发布时间】:2023-04-05 17:09:01
【问题描述】:

我正在尝试使用 JAX-WS 客户端生成这样的请求:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:alin="http://www.alinma.com" xmlns="http://www.alinma.com"> 
<soapenv:Header/>
<soapenv:Body>
    <alin:CustDtlsInqRq>
        <alin:MsgRqHdr>
            <RqUID>BPM11957T201508101626333904816</RqUID>
            <SCId>BPMP</SCId>
            <FuncId>24000000</FuncId>
            <RqMode>0</RqMode>
            <CustLangPref>En</CustLangPref>
            <CustId>
                <CIF>6060</CIF>
            </CustId>
            <AgentId>OprtSupportReviewer</AgentId>
        </alin:MsgRqHdr>
        <Body>
            <CIF>6060</CIF>
        </Body>
    </alin:CustDtlsInqRq>
</soapenv:Body>

但是请求是这样生成的:

<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/" xmlns="http://www.alinma.com">
<S:Header/>
<S:Body>
    <ns2:CustDtlsInqRq xmlns:ns2="http://www.alinma.com">
        <MsgRqHdr xmlns="">
            <RqUID>OLPM201508261333149660000020</RqUID>
            <SCId>BPMP</SCId>
            <FuncId>24000000</FuncId>
            <CustLangPref>En</CustLangPref>
            <CustId>
                <CIF>6060</CIF>
            </CustId>
        </MsgRqHdr>
        <Body xmlns="">
            <CIF>6060</CIF>
        </Body>
    </ns2:CustDtlsInqRq>
</S:Body>

添加的标签xmlns=""在服务器端产生问题 这是我的处理程序的代码,它用 SOAP 信封围绕请求

if (outboundProperty.booleanValue()) {

        try {
            SOAPMessage soapMessage = context.getMessage();

            SOAPEnvelope soapEnvelope = soapMessage.getSOAPPart().getEnvelope();
            soapEnvelope.addNamespaceDeclaration("", "http://www.alinma.com");
            // Grab the header of the SOAP envelop
            SOAPHeader soapHeader = soapEnvelope.getHeader();

            // Attach a new header if there is none...
            if (soapHeader == null) {
                soapHeader = soapEnvelope.addHeader();
            }

            soapMessage.saveChanges();
            soapMessage.writeTo(System.out); //TODO: remove this line (just for debugging)

        } catch (Exception e) {
            logger.error("Error Creating SOAP message", e);
        }  

    }

如何调整空的xmlns标签?

【问题讨论】:

  • 您是否使用了复杂的 XSD 元素,如果是这样,您可能需要正确定义内部和外部命名空间。
  • 我将此注解修改为@XmlType(name = "MsgRqHdr_Type", propOrder = { "rqUID", "scId", "funcId", "rqMode", "custLangPref" 的对象(MsgRqHdrType) ,“terminalId”,“terminalDesc”,“bankId”,“branchId”,“networkRefId”,“custId”,“usrId”,“sec”,“覆盖”,“agentId”,“clientDt”,“echoData”,“ version" },namespace="alinma.com") 但这并没有解决问题
  • 你需要设置targetNamespace元素

标签: java xml web-services soap jax-ws


【解决方案1】:

我可以解决问题。 我错误地删除了生成的文件 package-info.java,其中包含所有包类的标头命名空间定义

@javax.xml.bind.annotation.XmlSchema(namespace = "http://www.alinma.com", elementFormDefault = javax.xml.bind.annotation.XmlNsForm.QUALIFIED)
package com.ejada.sadadolp.bkf.mwservices.core;

【讨论】:

    猜你喜欢
    • 2012-04-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-04-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多