如何防止 JAXBElement在 CXF Web 服务客户端中生成?

发布于 2024-10-07 01:53:38 字数 286 浏览 0 评论 0 原文

我正在尝试使用 CXF 创建一个 Web 服务客户端来使用 WCF Web 服务。 当我使用 wsdl2java 时,它生成具有 JAXBElement 类型而不是 String 的对象。

我读到有关使用 jaxb Bindings.xml 文件设置generateElementProperty =“false”来尝试解决问题,但我正在使用的Web服务包含7个导入的模式。

如何在所有七个架构上指定 generateElementProperty="false",或者有没有办法将其应用于所有架构?

I'm trying to create a web service client using CXF to consume a WCF web service.
When I use wsdl2java it generates objects with JAXBElement types instead of String.

I read about using a jaxb bindings.xml file to set generateElementProperty="false" to try to fix the problem, but the web service I'm consuming contains 7 imported schemas.

How can I specify the generateElementProperty="false" on all seven schemas, or is there a way to apply it to all schemas?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

秋意浓 2024-10-14 01:53:38

您必须创建一个绑定文件,如下所示,这将在全局范围内应用并将其用作
wsdl2java - b“绑定.txt”“wsdl”

<jaxb:bindings version="2.1" 
xmlns:jaxb="http://java.sun.com/xml/ns/jaxb" 
xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc" 
xmlns:xs="http://www.w3.org/2001/XMLSchema"> 
   <jaxb:globalBindings generateElementProperty="false"/> 
</jaxb:bindings> 

You have to create a binding file as below, this will get applied globally and use it as
wsdl2java - b "bindings.txt" "wsdl"

<jaxb:bindings version="2.1" 
xmlns:jaxb="http://java.sun.com/xml/ns/jaxb" 
xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc" 
xmlns:xs="http://www.w3.org/2001/XMLSchema"> 
   <jaxb:globalBindings generateElementProperty="false"/> 
</jaxb:bindings> 
木森分化 2024-10-14 01:53:38

请注意,在我的例子中,我必须在 jaxb 绑定文件中使用 来摆脱 @Endpoint 中的 JAXBElement 请求和响应包装器

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:jaxb="http://java.sun.com/xml/ns/jaxb" xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc" elementFormDefault="qualified" attributeFormDefault="unqualified" jaxb:extensionBindingPrefixes="xjc" jaxb:version="2.1">
    <xs:annotation>
        <xs:appinfo>
            <jaxb:globalBindings>
                <xjc:simple /><!-- it did only work after adding this -->
            </jaxb:globalBindings>
        </xs:appinfo>
    </xs:annotation>
</xs:schema>

Note that in my case I had to use <xjc:simple in my jaxb binding file to get rid of the JAXBElement request and response wrappers in the @Endpoint:

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:jaxb="http://java.sun.com/xml/ns/jaxb" xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc" elementFormDefault="qualified" attributeFormDefault="unqualified" jaxb:extensionBindingPrefixes="xjc" jaxb:version="2.1">
    <xs:annotation>
        <xs:appinfo>
            <jaxb:globalBindings>
                <xjc:simple /><!-- it did only work after adding this -->
            </jaxb:globalBindings>
        </xs:appinfo>
    </xs:annotation>
</xs:schema>
放飞的风筝 2024-10-14 01:53:38

如果我们使用与 Jakarta EE 兼容的 CXF 版本,我们应该将语法更改为:

<?xml version="1.0" encoding="UTF-8"?>
<jaxws:bindings xmlns:jaxws="https://jakarta.ee/xml/ns/jaxws"
  xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:jxb="https://jakarta.ee/xml/ns/jaxb"
  xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/">
    <jxb:globalBindings generateElementProperty="false"/>
</jaxws:bindings>

If we are using a CXF version compatible with Jakarta EE, we should change the syntax to:

<?xml version="1.0" encoding="UTF-8"?>
<jaxws:bindings xmlns:jaxws="https://jakarta.ee/xml/ns/jaxws"
  xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:jxb="https://jakarta.ee/xml/ns/jaxb"
  xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/">
    <jxb:globalBindings generateElementProperty="false"/>
</jaxws:bindings>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文