faultString: java.io.IOException: No serializer found for class com.whcyit.axis.SimpleObject in registry org.apache.axis.encoding.TypeMappingDelegate@da3a1e
faultActor:
faultNode:
faultDetail:
{http://xml.apache.org/axis/}stackTrace:java.io.IOException: No serializer found for class com.whcyit.axis.SimpleObject in registry org.apache.axis.encoding.TypeMappingDelegate@da3a1e
at org.apache.axis.encoding.SerializationContext.serializeActual(SerializationContext.java:1429)
//创建调用对象Service service = new Service();Call call = null;call = (Call) service.createCall();//注册SimpleObject的序列化类型QName qn = new QName("urn:BeanService","SimpleObject");call.registerTypeMapping(SimpleObject.class, qn, new BeanSerializerFactory(SimpleObject.class, qn), new BeanDeserializerFactory(SimpleObject.class, qn));
全部代码示例如下:
//SimpleObject.java
//Web Service对象传递的对象package com.whcyit.axis;import java.io.Serializable; 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; }}
// SimpleObjectService.java
//服务程序
package com.whcyit.axis;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; } }
// SimpleObjectClient.java
//客户端调用文件
package com.whcyit.axis; import javax.xml.namespace.QName; import org.apache.axis.client.Call;import org.apache.axis.client.Service;import org.apache.axis.encoding.ser.BeanDeserializerFactory;import org.apache.axis.encoding.ser.BeanSerializerFactory; public class SimpleObjectClient { /** * @param args */ public static void main(String[] args) { String ret = ""; try { String wsdlUrl = "http://localhost:8080/axis/services/SimpleObjectService?wsdl"; String nameSpaceUri = "http://localhost:8080/axis/services/SimpleObjectService"; //String wsdlUrl = "http://10.68.19.24:8080/sample/services/SimpleObjectService?wsdl"; //String nameSpaceUri = "http://10.68.19.24:8080/sample/services/SimpleObjectService"; //创建调用对象 Service service = new Service(); Call call = null; call = (Call) service.createCall(); //注册SimpleObject的序列化类型 QName qn = new QName("urn:BeanService","SimpleObject"); call.registerTypeMapping(SimpleObject.class, qn, new BeanSerializerFactory(SimpleObject.class, qn), new BeanDeserializerFactory(SimpleObject.class, qn)); //调用sayHello System.out.println(">>>sayHello"); call.setOperationName(new QName(nameSpaceUri, "sayHello")); call.setTargetEndpointAddress(new java.net.URL(wsdlUrl)); ret = (String) call.invoke(new Object[] { "liu2" }); System.out.println("return value is " + ret); //调用getDesc System.out.println(">>>getString"); SimpleObject so = new SimpleObject(); so.setString("hello!"); QName getDescQn = new QName(nameSpaceUri, "getString"); call.setOperationName(getDescQn); call.setTargetEndpointAddress(new java.net.URL(wsdlUrl)); ret = (String) call.invoke(new Object[] { so }); System.out.println("return value is " + ret); //调用createSimpleObject 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 ex) { ex.printStackTrace(); } } }