我目前正在做一个使用Java中的JAX-WS Web服务的项目。
全局主题是:用户在本地创建一个对象,比如说
代理人
他先打电话
网络服务
并将其代理传递给网络服务。Web服务处理代理(修改其属性:例如生命点),并将其传递给另一个Web服务。这个调用是从第一个Web服务进行的,因此用户在这个过程中没有任何事情可做。
在多个Web服务链之后,用户检索已修改的Agent。
我的项目的目的是设计两个部分:
-
一
框架
指定前面描述的行为:Web服务、代理和迁移过程
-
一
演示应用程序
使用我的框架。主要区别在于添加了GUI和一个新类
阿凡达,扩展了特工
因此,迁移过程仍在“由框架”使用Agent对象进行。
以下代码显示了一个简单的示例,说明如何调用我的Web服务,托管我的Avatar,然后从服务中检索代理:
// connection to the server
URL endpoint= new URL("http://SERVER/tomcat/KiwiBidonDynamique/ServiceWebBidonDeDadou?wsdl");
QName serviceName=new QName("http://avatar/","ServeurKiwiBidonService");
Service service = Service.create(endpoint, serviceName);
WebService port = service.getPort(WebService.class);
Avatar myAvatar = new Avatar(1, "Jack the Ripper");
port.hostAgent(myAvatar);
// some process on the service...
Avatar myAvatarTransformed = (Avatar) port.getAgent("AgentNumberOne");
当我这样做时,我在最后一行得到一个例外:
Exception in thread "main" java.lang.ClassCastException: agent.Agent cannot be cast to avatar.Avatar
经过大量的日志阅读,我想原因是Web服务的工作方式。当被调用时,参数中给定的Avatar在JVM中进行编组,然后在服务上进行解编组,但是
该服务仅在解组时构造代理
这样做,它会截断特定于阿凡达的数据。然后,当我试图从服务中检索我的代理时,它无法被转换为阿凡达。
有没有一种方法可以在作为代理处理服务时保留头像信息?
我能以某种方式编写自己的编组/解编组吗?
谢谢。