建立一個簡單的webservice
阿新 • • 發佈:2018-12-11
1.我們需要匯入對應的jar,下面是對應的jar包,可以當然裡面包括幾個jpush的jar
2.編寫一個提供被外部的XXClientService
3.在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"> <welcome-file-list> <welcome-file>index.jsp</welcome-file> </welcome-file-list> <display-name>Archetype Created Web Application</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> </web-app>
4.編寫一個deploy.wsdd檔案同web.xml一個路徑:
<?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"> <!-- service標籤代表一個WebService服務 --> <service name="XXXClientService" provider="java:RPC"> <!-- 名稱空間,使用wsdl2java生成客戶端程式碼時,包路徑為:com.ll.server 假如釋出服務地址為:http://localhost:8080/axiswebservice/services/HelloWorld 如果屬性wsdlTargetNamespace不設定的話,生成客戶端程式碼的預設包路徑為:localhost.axiswebservice.services --> <parameter name="wsdlTargetNamespace" value="http://server.ll.com" /> <parameter name="wsdlServicePort" value="XXXClientService" /> <!-- 服務類路徑 --> <parameter name="className" value="com.XXXClientService" /> <!-- * 代表所有的方法都暴露 --> <parameter name="allowedMethods" value="*" /> <!--當前WebService的作用域,它有3個值,分別是:request每個請求、session每個使用者、application所有請求 --> <parameter name="scope" value="request" /> </service> </deployment>
5.新增一個server-config.wsddwe檔案同web.xml一個目錄
<?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="adminPassword" value="admin" /> <parameter name="attachments.Directory" value="D:\Tool_Work\apache-tomcat-8.0.32\webapps\axis\WEB-INF\attachments" /> <parameter name="dotNetSoapEncFix" value="true" /> <parameter name="enableNamespacePrefixOptimization" value="true" /> <parameter name="sendXMLDeclaration" value="true" /> <parameter name="attachments.implementation" value="org.apache.axis.attachments.AttachmentsImpl" /> <parameter name="sendXsiTypes" value="true" /> <requestFlow> <handler type="java:org.apache.axis.handlers.JWSHandler"> <parameter name="scope" value="session" /> </handler> <handler type="java:org.apache.axis.handlers.JWSHandler"> <parameter name="scope" value="request" /> <parameter name="extension" value=".jwr" /> </handler> </requestFlow> </globalConfiguration> <handler name="LocalResponder" type="java:org.apache.axis.transport.local.LocalResponder" /> <handler name="URLMapper" type="java:org.apache.axis.handlers.http.URLMapper" /> <handler name="Authenticate" type="java:org.apache.axis.handlers.SimpleAuthenticationHandler" /> <!-- 核心重點:服務釋出,name:表示釋出的service名 --> <service name="XXXClientService" provider="java:RPC"> <!-- 釋出的service介面類 --> <parameter name="className" value="com.XXXClientService" /> </service> <transport name="http"> <requestFlow> <handler type="URLMapper" /> <handler type="java:org.apache.axis.handlers.http.HTTPAuthHandler" /> </requestFlow> <parameter name="qs:list" value="org.apache.axis.transport.http.QSListHandler" /> <parameter name="qs:wsdl" value="org.apache.axis.transport.http.QSWSDLHandler" /> <parameter name="qs.list" value="org.apache.axis.transport.http.QSListHandler" /> <parameter name="qs.method" value="org.apache.axis.transport.http.QSMethodHandler" /> <parameter name="qs:method" value="org.apache.axis.transport.http.QSMethodHandler" /> <parameter name="qs.wsdl" value="org.apache.axis.transport.http.QSWSDLHandler" /> </transport> <transport name="local"> <responseFlow> <handler type="LocalResponder" /> </responseFlow> </transport> </deployment>