我正在使用 Java 项目中的 .NET Web 服务。我正在使用 Netbeans 8.2 并导入了 Web 服务。当我创建复杂对象时,问题就出现了,Netbeans 或 Java 将实体转换为 JAXBElement 而不是 String 参数。
我的问题是如何以发送字符串、日期时间或双精度对象的方式配置或映射实体。
这是我的类,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;}
我最终切换到 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: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>