0

I'm consuming a .NET web service from my Java project. I'm using Netbeans 8.2 and imported the web service. The problem comes when I'm creating the complex object, Netbeans or Java translates the entity as JAXBElement instead of the String parameter.

JAXBElement<String>

My question is how to configure or map the entity in a way that sends a String, Datetime or double object.

This is my class that netbeans generates after import WS.

public class GeoCountriesEntity {

@XmlElement(name = "CountryId")
protected Integer countryId;
@XmlElementRef(name = "Description", namespace = "http://schemas.datacontract.org/2004/07/Entities.Enterprise.Geo", type = JAXBElement.class, required = false)
protected JAXBElement<String> description;
@XmlElementRef(name = "UserCode", namespace = "http://schemas.datacontract.org/2004/07/Entities.Enterprise.Geo", type = JAXBElement.class, required = false)
protected JAXBElement<String> userCode;}
Santosh b
  • 729
  • 1
  • 8
  • 19
Oscar Romero
  • 231
  • 1
  • 2
  • 11
  • Are you using CXF to import the WSDL? I am pretty sure that Netbeans 8.2 uses CXF ffor importing the WSDL then generating jaxb classes. I know there is a setting you can change see this question: https://stackoverflow.com/questions/4413281/how-do-i-prevent-jaxbelementstring-from-being-generated-in-a-cxf-web-service-c – Namphibian Aug 01 '18 at 05:16
  • @Namphibian thank you for your time. I found a similar solution. – Oscar Romero Aug 04 '18 at 03:06

1 Answers1

0

I ended up switching to Maven, then imported my web service, finally, append the next setting to my pom.xml

<bindingFiles>
   <bindigFile>${basedir}/jaxb-bindings.xml</bindigFile>
</bindingFiles>

Create a jaxb-binding.xml in my root project.

<jaxb:bindings version="2.0" xmlns:jaxb="http://java.sun.com/xml/ns/jaxb">
<jaxb:bindings>
    <jaxb:globalBindings generateElementProperty="false"/>
</jaxb:bindings>

This is my full pom.xml,

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>coremanagersystem</groupId>
<artifactId>CoreManagerSystem</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<build>
    <resources>
        <resource>
            <targetPath>META-INF</targetPath>
            <directory>src</directory>
            <includes>
                <include>jax-ws-catalog.xml</include>
                <include>wsdl</include>
            </includes>
        </resource>
        <resource>
            <directory>src/main/resources</directory>
        </resource>
    </resources>
    <plugins>
        <plugin>
            <groupId>org.jvnet.jax-ws-commons</groupId>
            <artifactId>jaxws-maven-plugin</artifactId>
            <version>2.3</version>
            <executions>
                <execution>
                    <goals>
                        <goal>wsimport</goal>
                    </goals>
                    <configuration>
                        <wsdlFiles>
                            <wsdlFile>localhost_52536/Enterprise/Geo/GeoCountries.svc.wsdl</wsdlFile>
                        </wsdlFiles>
                        <packageName>ws.geo</packageName>
                        <vmArgs>
                            <vmArg>-Djavax.xml.accessExternalSchema=all</vmArg>
                        </vmArgs>
                        <wsdlLocation>http://localhost:52536/Enterprise/Geo/GeoCountries.svc?wsdl</wsdlLocation>
                        <staleFile>${project.build.directory}/jaxws/stale/GeoCountries.svc.stale</staleFile>
                        <!-- THIS SAVE MY LIFE -->
                        <bindingFiles>
                            <bindigFile>${basedir}/jaxb-bindings.xml</bindigFile>
                        </bindingFiles>
                        <!-- THIS SAVE MY LIFE -->
                    </configuration>
                    <id>wsimport-generate-GeoCountries.svc</id>
                    <phase>generate-sources</phase>
                </execution>
            </executions>
            <dependencies>
                <dependency>
                    <groupId>javax.xml</groupId>
                    <artifactId>webservices-api</artifactId>
                    <version>2.0</version>
                </dependency>
            </dependencies>
            <configuration>
                <sourceDestDir>${project.build.directory}/generated-sources/jaxws-wsimport</sourceDestDir>
                <xnocompile>true</xnocompile>
                <verbose>true</verbose>
                <extension>true</extension>
                <catalog>${basedir}/src/jax-ws-catalog.xml</catalog>
            </configuration>
        </plugin>
    </plugins>
</build>
<dependencies>
    <dependency>
        <groupId>org.glassfish.metro</groupId>
        <artifactId>webservices-rt</artifactId>
        <version>2.3</version>
    </dependency>
</dependencies>
<properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <maven.compiler.source>1.8</maven.compiler.source>
    <maven.compiler.target>1.8</maven.compiler.target>
</properties>
<name>Core Manager System</name>
<description>Handle the core information for your applications.</description>

Oscar Romero
  • 231
  • 1
  • 2
  • 11