一、服务端WebService
1.服务端环境配置
MyEclipse 10.0、Tomcat6.0、JDK6.0。
2.下载axis相关jar包。
3.创建webservice。
- 打开MyEclipse,新建web工程。
- 在WEB-INF目录先添加wsdd文件(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="webCallService" provider="java:RPC"> <parameter name="className" value="com.gc.Login"/> <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配置如下,
<?xml version="1.0" encoding="UTF-8"?> <web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"> <display-name></display-name> <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> <welcome-file-list> <welcome-file>index.jsp</welcome-file> </welcome-file-list> </web-app>
服务测试类,
public class Login { public String callService(String str1,String str2){ //逻辑代码... StringBuffer sb = new StringBuffer(); sb.append(str1); sb.append("->"); sb.append(str2); //... return sb.toString(); } }
4.测试是否连接成功。http://localhost:8088/webservice/services/webCallService?wsdl
连接成功如下所示,
<?xml version="1.0" encoding="UTF-8"?> <wsdl:definitions targetNamespace="http://localhost:8088/webservice/services/webCallService" xmlns:apachesoap="http://xml.apache.org/xml-soap" xmlns:impl="http://localhost:8088/webservice/services/webCallService" xmlns:intf="http://localhost:8088/webservice/services/webCallService" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:wsdlsoap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:xsd="http://www.w3.org/2001/XMLSchema"> <!--WSDL created by Apache Axis version: 1.2.1 Built on Jun 14, 2005 (09:15:57 EDT)--> <wsdl:message name="callServiceResponse"> <wsdl:part name="callServiceReturn" type="xsd:string"/> </wsdl:message> <wsdl:message name="callServiceRequest"> <wsdl:part name="str1" type="xsd:string"/> <wsdl:part name="str2" type="xsd:string"/> </wsdl:message> <wsdl:portType name="Login"> <wsdl:operation name="callService" parameterOrder="str1 str2"> <wsdl:input message="impl:callServiceRequest" name="callServiceRequest"/> <wsdl:output message="impl:callServiceResponse" name="callServiceResponse"/> </wsdl:operation> </wsdl:portType> <wsdl:binding name="webCallServiceSoapBinding" type="impl:Login"> <wsdlsoap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http"/> <wsdl:operation name="callService"> <wsdlsoap:operation soapAction=""/> <wsdl:input name="callServiceRequest"> <wsdlsoap:body encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="http://gc.com" use="encoded"/> </wsdl:input> <wsdl:output name="callServiceResponse"> <wsdlsoap:body encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="http://localhost:8088/webservice/services/webCallService" use="encoded"/> </wsdl:output> </wsdl:operation> </wsdl:binding> <wsdl:service name="LoginService"> <wsdl:port binding="impl:webCallServiceSoapBinding" name="webCallService"> <wsdlsoap:address location="http://localhost:8088/webservice/services/webCallService"/> </wsdl:port> </wsdl:service> </wsdl:definitions>
服务端到此已完成。续篇Android调用Java WebSevice篇之二