<operation name="方法名" returnType="方法返回数据类型">
<parameter name="参数名" type="参数的数据类型" mode="参数的模式"/>
</operation>
如果方法有多个参数则要注意参数描述的顺序必须和方法中定义的参数的顺序和数据类型相同。
3、数据类型的描述方法。谈到数据类型的描述你就需要注意你的server-config.wsdd文件开头的定义:
<deployment name="defaultClientConfig"
xmlns="http://xml.apache.org/axis/wsdd/"
xmlns:java="http://xml.apache.org/axis/wsdd/providers/java"
xmlns:handler="http://xml.apache.org/axis/wsdd/providers/handler">
大家注意到没有,在这儿有这么一段文字xmlns:java="http://xml.apache.org/axis/wsdd/providers/java",这段文字就是告诉你在使用数据类型描述时要使用JAVA的数据类型。你可以这样写返回类型为String的定义<operation name="方法名" returnType="java:String"/>,你也可以写成<operation name="方法名" returnType="xsd:string"/>但最好要在deployment元素中定义xmlns:xsd="http://www.w3.org/2001/XMLSchema"。
当然,在WSDD中还有其它的元素可以定义,具体可以参考http://www.osmoticweb.com/axis-wsdd/网站。
在你定义好WSDD文件后,你就可以启动TOMCAT,然后,我们来做个检验,在IE中键入
http://localhost:8090/你的站点名/services/服务名?wsdl,如果返回同图36相似的界面就表示你的Web Services发布成功了。
第六节 使用Java调用Web Services
我在这里使用一个简单JSP页面来调用Web Services。我先给出代码:
<%@page contentType="text/html"%>
<%@page pageEncoding="UTF-8"%>
<%@page import="org.apache.axis.client.Call,org.apache.axis.client.Service"%>
<%@page import="org.apache.axis.encoding.XMLType,org.apache.axis.utils.Options"%>
<%@page import="javax.xml.rpc.ParameterMode,javax.xml.namespace.QName"%>
<html>
<head><title>JSP Page</title></head>
<body>
<%
String endpoint = "http://localhost:8090/WEBServicesTest/services/HelloWorld";//这里为你的WEB SERVICES的访问路径;
String method = "hello";
Object[] param=null;
String myFund="";
try{
Service service = new Service();
Call call = (Call) service.createCall();
call.setTargetEndpointAddress(new java.net.URL(endpoint));
call.setOperationName(method);
myFund = (String) call.invoke(param);
}
catch(Exception e){
myFund=e.getMessage();
}
%>
<%=myFund%>
</body>
</html>
这个代码不是很复杂,相信大家都能够自己看懂,所以我在此不在讲解。在JSP中调用Webservice的关键是要引入六个包文件——org.apache.axis.client.Call、org.apache.axis.client.Service、org.apache.axis.encoding.XMLType






