Web Service的主要目标是跨平台的可互操作性。为了实现这一目标,Web Service 完全基于XML(可扩展标记语言)、XSD(XML Schema)等独立于平台、独立于软件供应商的标准,是创建可互操作的、分布式应用程序的新平台。
1:基础包,
2:配置文件,
deploy.wsdd
<deployment xmlns="http://xml.apache.org/axis/wsdd/"
xmlns:java="http://xml.apache.org/axis/wsdd/providers/java" target="_blank">
<service name="hello" provider="java:RPC">
<parameter name="className" value="HelloWorld" />
<parameter name="allowedMethods" value="getName" />
</service>
</deployment>
server-config.wsdd
<?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="sendMultiRefs" value="true" />
<parameter name="disablePrettyXML" value="true" />
<parameter name="dotNetSoapEncFix" value="true" />
<parameter name="enableNamespacePrefixOptimization" value="false" />
<parameter name="sendXMLDeclaration" value="true" />
<parameter name="sendXsiTypes" value="true" />
<parameter name="attachments.implementation"
value="org.apache.axis.attachments.AttachmentsImpl" />
</globalConfiguration>
<handler type="java:org.apache.axis.handlers.http.URLMapper"
name="URLMapper" />
<service name="hello" provider="java:RPC">
<parameter name="className" value="server.HelloWorld" />
<parameter name="scope" value="request" />
<parameter name="allowedMethods" value="*" />
<messageReceiver
class="org.apache.axis2.receivers.RawXMLINOutMessageReceiver" />
</service>
<transport name="http">
<requestFlow>
<handler type="URLMapper" />
</requestFlow>
</transport>
</deployment>
web.xml
<servlet>
<servlet-name>AxisServlet</servlet-name>
<servlet-class>org.apache.axis.transport.http.AxisServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>AxisServlet</servlet-name>
<url-pattern>/services/*</url-pattern>
</servlet-mapping>
3:实现类
客户端:
import org.apache.axis.client.Call;
import org.apache.axis.client.Service;
public class TestClient {
public static void main(String[] args) throws Exception {
String endpoint = "http://127.0.0.1/services/hello?wsdl";
Service service = new Service();
Call call = (Call) service.createCall();
call.setTargetEndpointAddress(new java.net.URL(endpoint));
call.setOperationName("backElectricKp");
String ret = (String) call.invoke(new Object[] { "xiexianyi" });
System.out.println(ret);
}
}
服务端:
public class HelloWorld {
public String getName(String name) {
return "hello World —>" + name;
}
}
完美~
例子:
http://files.cnblogs.com/files/xiexy/axis.zip