【问题标题】:Change JAX-WS output namespace prefix更改 JAX-WS 输出名称空间前缀
【发布时间】:2016-10-26 07:28:52
【问题描述】:

调用我们的 Web 服务希望我们返回以下 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 来提供我们的 Web 服务。以下是我们如何定义我们的 Web 服务接口:

@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;

}

这会产生以下返回文件:

<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 提供者生产其他系统想要的东西?

【问题讨论】:

    标签: web-services jax-ws


    【解决方案1】:

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

    服务消费者期望:

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

    但正在接​​收

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

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

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

    @WebMethod ()
        public void notifySmsDeliveryReceipt(
    

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

    或者,您也可以将 @WebMethod 更改为所需/指示的操作名称:

    @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>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多