JAX-WS:为什么嵌套元素在“"”中。命名空间? [英] JAX-WS: why nested elements are in "" namespace?

查看:189
本文介绍了JAX-WS:为什么嵌套元素在“"”中。命名空间?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

拥有以下玩具服务

@WebService(targetNamespace="http://www.example.org/stock")
@SOAPBinding(style=Style.RPC,parameterStyle=ParameterStyle.WRAPPED)
public class GetStockPrice {
    @WebMethod(operationName="GetStockPrice",action="urn:GetStockPrice")
    @WebResult(partName="Price")
    public Double getPrice(
            @WebParam(name="StockName")
            String stock
        ) {
        return null;
    }
}

JAX-WS生成的客户端创建SOAP消息StockName参数没有命名空间:

JAX-WS-generated client creates a SOAP message where StockName parameter has no namespace:

<?xml version='1.0' encoding='UTF-8'?>
<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
  <S:Body>
    <ns2:GetStockPrice xmlns:ns2="http://www.example.org/stock">
      <StockName>IBM</StockName>
    </ns2:GetStockPrice>
  </S:Body>
</S:Envelope>

我希望并希望StockName生成为

I would expect and wish StockName to be generated as

  <ns2:StockName>IBM</ns2:StockName>

即。在目标名称空间中,而不是在匿名名称空间中(ns2不是默认的,就我从消息中看到的那样)。

i.e. in the target namespace, not in the anonymous one (ns2 is not default, as far as I can see from the message).

我想知道如何制作JAX-WS将目标命名空间添加到消息的嵌套元素中?

I wonder how to make JAX-WS to add the target namespace to the nested elements of the message?

尝试将名称空间指定为WebParam注释没有改变任何内容,因为在使用RPC时会忽略此参数。

An attempt to specify the namespace to WebParam annotation changed nothing as this param is ignored when RPC is used.

或者......这是否意味着RPC风格的参数始终是匿名的?

Or... Does it mean that parameters in RPC-style are always anonymous?

更新

傻傻的我。部分解决了。我必须做的是

Silly me. Partially solved. What I had to do is


  • style = Document,为元素启用目标命名空间

  • param style = Wrapped,以启用顶级元素

  • 为WebParam指定目标命名空间(为什么不使用服务?文档说应该使用服务命名空间)

即:

@WebService(targetNamespace="http://www.example.org/stock")
@SOAPBinding(style=Style.DOCUMENT,parameterStyle=ParameterStyle.WRAPPED)
public class GetStockPrice {
    @WebMethod(operationName="GetStockPrice",action="urn:GetStockPrice")
    @WebResult(partName="Price")
    public Double getPrice(
            @WebParam(name="StockName",targetNamespace="http://www.example.org/stock")
            String stock
        ) {
        return null;
    }
}

仍然,客户端仍然期望没有任何命名空间的返回值,即使我试图宣布提供一个。这很令人困惑。

Still, client still expects return value without any namespace, even if I try to declare provide one. This is confusing.

推荐答案

根据WSI-Basic Profile,这种行为是正确的。如果你看一下:

This behavior is proper per the WSI-Basic Profile. If you look at:

http://www.ws-i.org/profiles/basicprofile-1.1.html#Part_Accessors

4.7.20节,断言R2735具体说明对于RPC / Literal,必须将部分访问器元素放在没有namspace的元素中。

section 4.7.20, assertion R2735 specifically states that for RPC/Literal, the part accessor elements must be put in elements with no namspace.

这篇关于JAX-WS:为什么嵌套元素在“&quot;”中。命名空间?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆