axis client 自定义对象序列化

axis 自定义对象序列化,只使用了beanMapping,未说明typeMapping,arrayMapping (参考axis user guide)基于Axis的自定义对象序列化

1. 在Axis服务端,注册自定义对象的序列化/反序列化器
主要是修改axis安装目录下WEB-INF/server-config.wsdd文件。

 

 

PS: cannot config use="literal" in

 

2. 在Axis客户端,注册自定义对象的序列化/反序列化器。

public static void main(String[] args) { // TODO Auto-generated method stub String wsdlUrl = "http://localhost:8080/xxx/services/SimpleObjectService?wsdl"; String nameSpaceUri = "http://localhost:8080/xxx/services/SimpleObjectService"; try { Service service = new Service(); Call call = null; call = (Call) service.createCall(); QName qn = new QName("urn:BeanService", "SimpleObject"); call.registerTypeMapping(SimpleObject.class, qn, new BeanSerializerFactory(SimpleObject.class, qn), new BeanDeserializerFactory(SimpleObject.class, qn)); System.out.println(">>>createSimpleObject"); QName getObjectQn = new QName(nameSpaceUri, "createSimpleObject"); call.setOperationName(getObjectQn); call.setTargetEndpointAddress(new java.net.URL(wsdlUrl)); SimpleObject rtnSO = (SimpleObject) call.invoke(new Object[] { new Integer(1), new Float(0.1f), "liu2" }); System.out.println("return object " + rtnSO.getString()); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } }

 

3.服务器端代码:

public class SimpleObjectService { public String sayHello(String name) { return "Hello " + name + "!"; } public String getString(SimpleObject obj) { System.out.println("SimpleObjectService getString invoked!"); return "return by serviced:" + obj.getString(); } public SimpleObject createSimpleObject(int i, float f, String str) { System.out.println("SimpleObjectService createSimpleObject invoked!"); SimpleObject so = new SimpleObject(); so.setInt(i); so.setFloat(f); so.setString(str); return so; } }

 

public class SimpleObject implements Serializable { private static final long serialVersionUID = -6414428095965735488L; private int i = 0; private float f = 0.0f; private String str = ""; public SimpleObject() { } public float getFloat() { return f; } public void setFloat(float f) { this.f = f; } public int getInt() { return i; } public void setInt(int i) { this.i = i; } public String getString() { return str; } public void setString(String str) { this.str = str; } }

 

 

你可能感兴趣的:(WebService)