服务端:
package wsdd;
import axisserver.Fun;
public class TestWSDD {
private Fun f = new Fun();//自定义的对象
public Fun getType(String type){//要调用的方法
this.f.setName("fff");
return f;//返回自定义对象
}
}
deploy.wsdd:
<deployment xmlns="http://xml.apache.org/axis/wsdd/" xmlns:java="http://xml.apache.org/axis/wsdd/providers/java">
<service name="TestWSDD" provider="java:RPC">
<parameter name="className" value="wsdd.TestWSDD"/>
<parameter name="allowedMethods" value="*"/>
<beanMapping languageSpecificType="java:axisserver.Fun"
qname="ns7:TestWSDD" xmlns:ns7="TestWSDD"/> //注意此处
</service>
</deployment>
客户端:
package axisclientwsdd;
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;
import axisserver.Fun;
public class AXISCLientWSDD {
public static void main(String[] args) {
try {
String endpoint = "http://localhost/AXISExam/services/TestWSDD";//与WSDL唯一的不同;指明服务所在位置
Service service = new Service();//创建一个Service实例
call = (Call) service.createCall();
call.setTargetEndpointAddress(new java.net.URL(endpoint));//为Call设置服务的位置
QName qn = new QName("TestWSDD","TestWSDD");//与WSDD设置的要一致!
call.registerTypeMapping(Fun.class,qn, new BeanSerializerFactory(Fun.class, qn), new BeanDeserializerFactory(Fun.class, qn));
call.setOperationName(new QName("urn:TestWSDD","getType"));
Fun f2 = (Fun)call.invoke(new Object[]{});
System.out.println(f2.getName());
}
catch (Exception ex) {
System.err.println(ex.toString());
}
}
}