Java SOAP XML 序列化错误

标签 java xml soap deserialization xmlserializer

我有一个托管一些网络服务的 .net 服务器。

我正在制作一个Java客户端。我使用 Apache CFX 根据给定的 wsdl 文件自动创建一些有用的类。

但是,当我用 Java 调用 Web 服务时,出现以下错误:

Exception in thread "Thread-3" javax.xml.ws.soap.SOAPFaultException: The formatter threw an exception while trying to deserialize the message: There was an error while trying to deserialize parameter http://localhost/MyService:ManualAddress. The InnerException message was 'There was an error deserializing the object of type Company.Product.Application.Services.DataContracts.LetterProcessManualAddress. The '/' character, hexadecimal value 0x2F, cannot be included in a name. Line 1, position 2119.'.  Please see InnerException for more details.
at com.sun.xml.internal.ws.fault.SOAP11Fault.getProtocolException(Unknown Source)
at com.sun.xml.internal.ws.fault.SOAPFaultBuilder.createException(Unknown Source)
at com.sun.xml.internal.ws.client.sei.SyncMethodHandler.invoke(Unknown Source)
at com.sun.xml.internal.ws.client.sei.SyncMethodHandler.invoke(Unknown Source)
at com.sun.xml.internal.ws.client.sei.SEIStub.invoke(Unknown Source)
at $Proxy37.processEnrollmentTraditionalDeficiency(Unknown Source)
at com.parc.peimage.PEFormViewer$3.run(PEFormViewer.java:2582)
at java.lang.Thread.run(Unknown Source)

手动地址是 JAXBElement,由于此错误,我的 XML 未正确创建。

这是我创建地址的代码:

// SET manual address variables
com.parc.SomeCompanyAPI.Address MA;
MA = new Address();
MA.setAddressInCareOfName(new JAXBElement <String>  (new QName("http://example.com/SampleService"), String.class, "MyName"));
MA.setAddressLineOne(new JAXBElement <String>  (new QName("http://example.com/SampleService"), String.class, "MyAdd1"));
MA.setAddressLineTwo(new JAXBElement <String> (new QName("http://example.com/SampleService"), String.class, "MyAdd2"));
MA.setCity(new JAXBElement <String> (new QName("http://example.com/SampleService"), String.class, "MyAdd3"));
MA.setStateCode(new JAXBElement <String> (new QName("http://example.com/SampleService"), String.class, "MyAdd4"));
MA.setZipCode(new JAXBElement <String> (new QName("http://example.com/SampleService"), String.class, "MyAdd5"));
JAXBElement <Address> majax = new JAXBElement <Address> (new QName("http://example.com/SampleService"), Address.class, MA);
letter.setAddress(majax);
JAXBElement <String> provider = new JAXBElement<String>(new QName("http://example.com/SampleService"), String.class, "bob");
letter.setProviderName(provider);

提前致谢!

最佳答案

对我来说,CXF 会生成采用 JAXBElement 而不是字符串的 setter,这似乎很奇怪。可能的解决方案可以在 this answer 中找到。 ,generateElementProperty 属性进一步记录在 WSIT Tutorial 中。 .

您在这里遇到的异常是因为您使用了错误的构造函数 QName ,您应该指定命名空间 URI 和元素的本地名称作为参数。

关于Java SOAP XML 序列化错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8322008/

相关文章:

java - apache-commons-dbutils 可以将 beans 转换为 SQL 语句吗?

java - '(number)' 的正则表达式

java - 如何用Slick2D创​​建圆弧?

java - InflateException 和 IllegalStateException,同时将 fragment 用于自定义列表

java - 解码为soap webservice 中的通用类型 xml 中的任何类型

java - SAXParseException;源代码解析 : Cannot resolve the name '...' to a(n) 'type definition' component

xml - 保留多个xsd :any with JAXB using @XmlAnyElement

php - CodeIgniter Web 服务客户端

android - 如何删除我:type ="d:string" from PropertyInfo of SOAP in KSOAP2 Android

REST 与 SOAP 可演化性