java JAX-WS:为什么嵌套元素在“”命名空间中?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5793352/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-30 12:46:58  来源:igfitidea点击:

JAX-WS: why nested elements are in "" namespace?

javajax-wsrpcxml-namespaces

提问by Vladimir Dyuzhev

Having a toy service as below

有玩具服务如下

@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-generated client creates a SOAP message where StockName parameter has no namespace:

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

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

I would expect and wish StockName to be generated as

我希望并希望将 StockName 生成为

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

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

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

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

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

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

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

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

或者... 是不是意味着 RPC 风格的参数总是匿名的?

UPDATE

更新

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

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

  • style=Document, to enable target namespaces for elements
  • param style=Wrapped, to enable top level element
  • specify target namespace for WebParam (why service one is not used? documentation says service namespace should be used)
  • style=Document,为元素启用目标命名空间
  • param style=Wrapped, 启用顶级元素
  • 为 WebParam 指定目标命名空间(为什么不使用服务一?文档说应该使用服务命名空间)

That is:

那是:

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

尽管如此,即使我尝试声明提供一个,客户端仍然期望没有任何命名空间的返回值。这令人困惑。

采纳答案by Daniel Kulp

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

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

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

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

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

第 4.7.20 节,断言 R2735 明确指出,对于 RPC/Literal,部分访问器元素必须放在没有命名空间的元素中。

回答by Vidhya - Vidhyadharan

I too have the same problem . i developed webservice clientusing JAX-WS, with SOAP UI simulation.My webservice client is working fine. but when i test with real server (axis web service). I got null values.

我也有同样的问题。我使用 JAX-WS 和 SOAP UI 模拟开发了网络服务客户端。我的网络服务客户端工作正常。但是当我使用真实服务器(轴网络服务)进行测试时。我得到了空值。

SOUP UI simulation response like this

SOUP UI模拟响应是这样的

    <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:web="http://webservice.aml.infrasofttech.biz" xmlns:dat="http://dataobject.aml.infrasofttech.biz">
   <soapenv:Header/>
   <soapenv:Body>
      <web:getCIPMatchResponse>
         <!--1 or more repetitions:-->
         <web:getCIPMatchReturn>
            <dat:countries>?</dat:countries>
            <dat:dob>?</dat:dob>
            <dat:fullName>?</dat:fullName>
            <dat:isError>?</dat:isError>
            <dat:listName>?</dat:listName>
            <dat:passport>?</dat:passport>
            <dat:percentage>?</dat:percentage>
            <dat:sdnId>?</dat:sdnId>
            <dat:sdnName>?</dat:sdnName>
         </web:getCIPMatchReturn>
      </web:getCIPMatchResponse>
   </soapenv:Body>
</soapenv:Envelope>

But in the server it response with out namespace like this..

但是在服务器中,它以这样的命名空间响应..

        <countries>?</countries>
        <dob>?</dob>
        <fullName>?</fullName>
        <isError>?</isError>
        <listName>?</listName>
        <passport>?</passport>
        <percentage>?</percentage>
        <sdnId>?</sdnId>
        <sdnName>?</sdnName>

The JAX-WS generated code looks like this.

JAX-WS 生成的代码如下所示。

  @XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "SdnBean", namespace = "http://dataobject.aml.infrasofttech.biz", propOrder = {
    "countries",
    "dob",
    "fullName",
    "isError",
    "listName",
    "passport",
    "percentage",
    "sdnId",
    "sdnName"
})
public class SdnBean {

Then i have change the client jax-ws code @XmlType as shown below

然后我更改了客户端 jax-ws 代码 @XmlType,如下所示

@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "", propOrder = {
    "countries",
    "dob",
    "fullName",
    "isError",
    "listName",
    "passport",
    "percentage",
    "sdnId",
    "sdnName"
})
public class SdnBean {

Now this will bind the soap response without namespace.

现在这将绑定没有命名空间的soap响应。