简体   繁体   中英

Send String instead of JAXBElement<String>

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 <字符串>

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;}

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>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM