2011-11-30 40 views
1

我有一个.NET服务器托管一些Web服务。Java SOAP XML序列化错误

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

然而,当我做在Java中调用WebService的我得到以下错误:

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

提前感谢!

回答

2

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

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