更改 JAX-WS 输出名称空间前缀

Change JAX-WS output namespace prefix

调用我们的 Web 服务希望我们 return 以下 XML:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:loc="http://www.csapi.org/schema/parlayx/sms/notification/v2_2/local">
    <soapenv:Header />
    <soapenv:Body>
        <loc:notifySmsDeliveryReceiptResponse />
    </soapenv:Body>
</soapenv:Envelope>

我们使用 JAX-WS 来提供我们的网络服务。以下是我们如何定义我们的网络服务接口:

@BindingType(value = javax.xml.ws.soap.SOAPBinding.SOAP11HTTP_MTOM_BINDING)
@WebService (targetNamespace = "http://www.csapi.org/schema/parlayx/sms/notification/v2_2/local")
@HandlerChain(file = "deliverysoaphandler.xml")
@SOAPBinding(style = Style.DOCUMENT)
public interface DeliveryService {

    @WebMethod ()
    public void notifySmsReception(
            @WebParam(name = "correlator", targetNamespace = "http://www.csapi.org/schema/parlayx/sms/notification/v2_2/local") @XmlElement(required = true) String correlator, 
            @WebParam(name = "message", targetNamespace = "http://www.csapi.org/schema/parlayx/sms/notification/v2_2/local") @XmlElement(required = true) Message message

            ) throws DeliveryException;

}

这会生成以下 return 文档:

<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
   <SOAP-ENV:Header/>
   <S:Body>
      <ns2:notifySmsReceptionResponse xmlns:ns2="http://www.csapi.org/schema/parlayx/sms/notification/v2_2/local"/>
   </S:Body>
</S:Envelope>

我们认为该文档与调用系统所期望的一样重要但被拒绝,因为 1) 命名空间大写,2) 重复相同的命名空间引用和 3) 中间有一个命名空间声明文档。

无论如何我都可以说服 JAX-WS 提供者生成其他系统想要的东西吗?

根据此描述,我不确定命名空间是否有问题。

服务消费者期望:

<soapenv:Body>
    <loc:notifySmsDeliveryReceiptResponse />
</soapenv:Body>

但正在接收

   <S:Body>
      <ns2:notifySmsReceptionResponse xmlns:ns2="..."/>
   </S:Body>

表示对不同操作名称的响应。

尝试将您的服务端点接口 WebMethod 方法名称更改为:

@WebMethod ()
    public void notifySmsDeliveryReceipt(

这样做还需要您更改实现中的方法名称 class(否则它将不再编译)。

或者,您也可以将 @WebMethod 更改为 desired/indicated 操作名称:

@WebMethod (operationName="notifySmsDeliveryReceipt")
public void notifySmsReception(

服务现在应该产生:

   <S:Body>
      <ns2:notifySmsDeliveryReceiptResponse xmlns:ns2="http://www.csapi.org/schema/parlayx/sms/notification/v2_2/local"/>
   </S:Body>