发送字符串而不是JAXBElement <string>

时间:2018-08-01 03:34:52

标签: java .net soap service jaxb

我正在使用Java项目中的.NET Web服务。我正在使用Netbeans 8.2并导入了Web服务。当我创建复杂对象时,问题就来了,Netbeans或Java将实体转换为JAXBElement而不是String参数。

JAXBElement<String>

我的问题是如何以发送String,Datetime或double对象的方式配置或映射实体。

这是我在NetBeans导入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;}

1 个答案:

答案 0 :(得分:0)

我最终切换到Maven,然后导入了我的Web服务,最后,将下一个设置附加到我的pom.xml

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

在我的根项目中创建一个jaxb-binding.xml。

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

这是我的完整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>