50

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?

Jens
  • 63,364
  • 15
  • 92
  • 104
ScArcher2
  • 82,195
  • 42
  • 116
  • 158

2 Answers2

71

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> 
priya
  • 930
  • 1
  • 10
  • 15
  • 8
    http://cxf.apache.org/docs/maven-cxf-codegen-plugin-wsdl-to-java.html For instructions on how to set a bindings file using the maven plugin. – ScArcher2 Jan 19 '11 at 16:36
  • 1
    It would be better to use a more specific file extensions for the mapping file such as `.xml`or `.xjb` as proposed here http://docs.oracle.com/cd/E17802_01/webservices/webservices/docs/2.0/tutorial/doc/JAXBUsing4.html#wp148366 – schnatterer Apr 11 '14 at 07:18
  • 1
    And if you already have a jaxb:globalBindings in your XSD or WSDL, just add the generateElementProperty="false" attribute to that node. No need to add another binding.xml in this case. – Alain Pannetier May 17 '15 at 07:00
  • @ScArcher2 Awesome.. Thanks.. I am using third party wsdl so made this xml file as shown in the main answer and defined it in pom.xml as shown in the link. It worked. – Mital Pritmani Aug 04 '15 at 13:38
  • If I use this binding file the data posted and returned is empty. – Panu Haaramo Sep 09 '15 at 08:40
  • For creating a dynamic client, use the following: `JaxWsDynamicClientFactory.newInstance().createClient("wsdl", Arrays.asList("bindings.txt"))` – Gat Mar 18 '18 at 10:03
0

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>
yglodt
  • 12,552
  • 14
  • 82
  • 121