使用JAX-WS的SOAP消息中的嵌套标记中没有名称空间 [英] No namespace in nested tags in SOAP message with JAX-WS

查看:48
本文介绍了使用JAX-WS的SOAP消息中的嵌套标记中没有名称空间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用JAX-WS和wsimport编写一个使用给定Web服务的Java应用程序.它发送给服务的SOAP消息大部分是正确的.但是,传递给服务函数的参数中有一个是字符串数组.尽管在SOAP XML中为数组本身指定了适当的名称空间,但是元素(以下消息中的"parm")没有名称空间.这会导致服务失败.

I am trying to write a Java application that consumes a given web service, using JAX-WS and wsimport. The SOAP message that it sends to the service is mostly correct. However, on of the parameters passed to the service function is an array of strings. Although the array itself is given the proper namespace in the SOAP XML, elements ('parm' in the message below) have no namespace. This causes the service to fail.

<?xml version="1.0" ?>
<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
    <S:Body>
        <ns2:Submit xmlns:ns2="http://www.acme.com/service/wsdl">
            <ns2:service>SomeJob</ns2:service>
            <ns2:parms>
                <parm>someparam</parm>
                <parm>anotherparam</parm>
            </ns2:parms>
        </ns2:Submit>
    </S:Body>
</S:Envelope>

<parm>元素应该已读取<ns2:parm>,或者<Submit>标记也可以定义默认的名称空间<Submit xmlns="http://www.acme.com/service/wsdl">(这是该服务在示例SOAP消息中建议的内容).

The <parm> elements should have read <ns2:parm>, or alternatively the <Submit> tag could have defined a default namespace <Submit xmlns="http://www.acme.com/service/wsdl"> (that is what the service suggests in an example SOAP message).

这个问题确实类似于> JAX-WS:为什么嵌套元素在"中命名空间?.但是,将样式从RPC/文字更改为文档/包装可以解决此问题,而在我的情况下,服务是从文档/包装开始的.

This question does resemble the one in JAX-WS: why nested elements are in "" namespace?. However there changing the style from RPC/Literal to Document/Wrapped solved the issue, while in my case the service is Document/Wrapped to begin with.

如何说服JAX-WS库在数组中的嵌套元素上生成名称空间?

How can I convince the JAX-WS library to generate namespaces on the nested elements in the array?

TIA, 耶隆(Jeroen)

TIA, Jeroen

更新:似乎可以编辑生成的代码.有人建议在@XmlElement行中添加名称空间属性,然后在生成的数组类型中定义"parm":

Update: Editing the generated code appears to work. Someone suggested adding a namespace attribute to the @XmlElement line preceeding the definition of 'parm' in the generated array type:

@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "ArrayOfString", propOrder = {
    "parm"
})
public class ArrayOfString {

@XmlElement(nillable = true, namespace="http://www.acme.com/service/wsdl")
protected List<String> parm;
...
}

这将导致JAX-WS添加名称空间,并且可能会解决该问题.由于在这种情况下代码生成仅执行一次,因此编辑生成的代码是可以接受的.我还是想知道是否还有更好的解决方案.

This causes JAX-WS to add the namespace and will probably solve the issue. As code generation is, in this case, done only once, editing the generated code is acceptable. Still I wonder whether there isn't a better solution.

推荐答案

您还可以通过添加

elementFormDefault="qualified"

添加到Java @XmlSchema批注中-或者在您的情况下-添加到定义服务的XSD.

either to your Java @XmlSchema annotation - or in your case - to the XSD defining the service.

这篇关于使用JAX-WS的SOAP消息中的嵌套标记中没有名称空间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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