Recently, because the company used Web Services technology for Enterprise Application Integration (EAI)-related projects, the use of axis in response to technical staff cannot pass user-defined objects.
The error message is as follows:
Axisfault
Faultcode: {http://schemas.xmlsoap.org/soap/envelope/}server.userexception
Faultsubcode:
Faultstring: Java. Io. ioexception: No serializer found for class com. whcyit. axis. simpleobject in registry org. Apache. axis. encoding. typemappingdelegate @ da3a1e
Faultactor:
Faultnode:
Faultdetail:
{Detail 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)
Web services have been around for more than four years. Basically, Web Services is just a concept. With questions, I decided to give it a try. What is going on?
Finally, after more than two hours of testing, the problem was finally solved. The solution is as follows:
1. register the serialization/deserializer of custom objects on the axis server.
It is primarily to modify the WEB-INF/server-config.wsdd files under the axis installation directory.
<service name="SimpleObjectService" provider="java:RPC"> <parameter name="allowedMethods" value="*"/> <parameter name="className" value="com.whcyit.axis.SimpleObjectService"/> <beanMapping languageSpecificType="java:com.whcyit.axis.SimpleObject" qname="ns:SimpleObject" xmlns:ns="urn:BeanService"/></service>
Pay attention to the definition of service/beanmapping. In languagespecifictype, the class is defined. QNAME defines the class name.
2. register the serialization/deserialization tool of the custom object on the axis client.
The core code is as follows:
// Create a call object
Service = new service ();
Call call = NULL;
Call = (CALL) service. createcall ();
// Register the serialization type of simpleobject
QNAME Qn = new QNAME ("urn: beanservice", "simpleobject ");
Call. registertypemapping (simpleobject. Class, qN, new beanserializerfactory (simpleobject. Class, qN), new beandeserializerfactory (simpleobject. Class, qN ));
Sample Code:
// Simpleobject. Java
// The object passed by the web service object
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
// Service Program
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
// Client call File
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 ";
// Create a call object
Service = new service ();
Call call = NULL;
Call = (CALL) service. createcall ();
// Register the serialization type of simpleobject
QNAME Qn = new QNAME ("urn: beanservice", "simpleobject"); call. registertypemapping (simpleobject. class, qN, new beanserializerfactory (simpleobject. class, qN), new beandeserializerfactory (simpleobject. class, qN ));
// Call 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 );
// Call 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 );
// Call 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 ();}}}
// Server-config.wsdd
// Server configuration file
<?xml version="1.0" encoding="UTF-8"?>
<deployment xmlns="http://xml.apache.org/axis/wsdd/" xmlns:java="http://xml.apache.org/axis/wsdd/providers/java"> <globalConfiguration> <parameter name="adminPassword" value="admin"/> <parameter name="attachments.Directory" value="C:/eclipse/workspace/bookstore/WEB-INF/attachments"/> <parameter name="attachments.implementation" value="org.apache.axis.attachments.AttachmentsImpl"/> <parameter name="sendXsiTypes" value="true"/> <parameter name="sendMultiRefs" value="true"/> <parameter name="sendXMLDeclaration" value="true"/> <parameter name="axis.sendMinimizedElements" value="true"/> <requestFlow>