我正在为 SOAP Web 服务编写客户端。我正在使用库 CXF。使用简单的前端。还有 Aegis 数据绑定。服务器为 Web 方法提供了一个 Java 接口(名为 MediaService),我将该接口导入到客户端项目中。然后,我使用 MediaService.aegis.xml 文件为方法参数提供名称(以便它们不被命名以及在序列化请求时)。
这是我在客户端使用的代码:
ClientProxyFactoryBean factory = new ClientProxyFactoryBean();
factory.setDataBinding(new AegisDatabinding());
factory.setServiceClass(MediaService.class);
factory.setAddress(urlMediaServer);
MediaService service = (MediaService) factory.create();
final List<Reference> listeReferences = service.sendMedia(bu, media);
服务接口是这样的:
public interface MediaService
{
public List sendMedia(String bu, Media media) throws Exception;
}
我启用了 XML 流日志记录,以便查看发送到服务器的 XML 流以及它返回的流。
以下是流:
要求:
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<ns1:sendMedia xmlns:ns1="http://service.soclemedia.mycompany.com/">
<ns1:bu>sc_phx</ns1:bu>
<ns1:media>
<ns2:productId xmlns:ns2="http://bo.soclemedia.mycompany.com">TEST_CODE</ns2:productId>
<ns2:mediaName xmlns:ns2="http://bo.soclemedia.mycompany.com">test.png</ns2:mediaName>
</ns1:media>
</ns1:sendMedia>
</soap:Body>
</soap:Envelope>
回复:
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soap:Body>
<sendMediaResponse xmlns="http://service.soclemedia.mycompany.com">
<out xmlns="http://service.soclemedia.mycompany.com">
<ns1:Reference xmlns:ns1="http://bo.soclemedia.mycompany.com">
<subType xmlns="http://bo.soclemedia.mycompany.com">standard</subType>
<typeMedia xmlns="http://bo.soclemedia.mycompany.com">photo</typeMedia>
</ns1:Reference>
<ns1:Reference xmlns:ns1="http://bo.soclemedia.mycompany.com">
<subType xmlns="http://bo.soclemedia.mycompany.com">standard</subType>
<typeMedia xmlns="http://bo.soclemedia.mycompany.com">photo</typeMedia>
</ns1:Reference>
</out>
</sendMediaResponse>
</soap:Body>
</soap:Envelope>
服务被调用,它回复并且客户端收到正确的回复。但在客户端中,进行 Web 服务调用的 service.sendMedia(bu, media) 行返回 null。反序列化回复有问题。您知道出了什么问题以及如何解决吗?
此致。
更新:
我忘了提到当我调用这个方法时:
MediaService service = (MediaService) factory.create();
我收到此错误:
INFO: Creating Service {http://service.soclemedia.mycompany.com/}MediaService from class com.mycompany.soclemedia.service.MediaService
24 nov. 2011 15:18:37 org.apache.cxf.aegis.type.XMLTypeCreator <clinit>
INFO: Could not set aegis schema. Not validating.
java.lang.UnsupportedOperationException: This parser does not support specification "null" version "null"
at javax.xml.parsers.DocumentBuilderFactory.setSchema(DocumentBuilderFactory.java:489)
at org.apache.cxf.aegis.type.XMLTypeCreator.<clinit>(XMLTypeCreator.java:125)
at org.apache.cxf.aegis.AegisContext.createRootTypeCreator(AegisContext.java:122)
at org.apache.cxf.aegis.AegisContext.createTypeCreator(AegisContext.java:111)
at org.apache.cxf.aegis.AegisContext.initialize(AegisContext.java:153)
at org.apache.cxf.aegis.databinding.AegisDatabinding.initialize(AegisDatabinding.java:229)
at org.apache.cxf.service.factory.AbstractServiceFactoryBean.initializeDataBindings(AbstractServiceFactoryBean.java:86)
at org.apache.cxf.service.factory.ReflectionServiceFactoryBean.buildServiceFromClass(ReflectionServiceFactoryBean.java:438)
at org.apache.cxf.service.factory.ReflectionServiceFactoryBean.initializeServiceModel(ReflectionServiceFactoryBean.java:501)
at org.apache.cxf.service.factory.ReflectionServiceFactoryBean.create(ReflectionServiceFactoryBean.java:241)
at org.apache.cxf.frontend.AbstractWSDLBasedEndpointFactory.createEndpoint(AbstractWSDLBasedEndpointFactory.java:101)
at org.apache.cxf.frontend.ClientFactoryBean.create(ClientFactoryBean.java:90)
at org.apache.cxf.frontend.ClientProxyFactoryBean.create(ClientProxyFactoryBean.java:153)
...
这是我的 cxf.xml:
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:cxf="http://cxf.apache.org/core"
xsi:schemaLocation="http://cxf.apache.org/core http://cxf.apache.org/schemas/core.xsd">
<cxf:bus>
<cxf:features>
<cxf:logging/>
</cxf:features>
</cxf:bus>
</beans>
更新 2:
这是我的 MediaService.aegis.xml:
<mappings>
<mapping>
<method name="sendMedia">
<parameter index="0" mappedName="bu"/>
<parameter index="1" mappedName="media"/>
<return-type componentType="com.mycompany.soclemedia.bo.Reference" />
</method>
</mapping>
</mappings>