웹 서비스의 실현

4704 단어 webservice
1. 먼저 WEB 프로젝트 를 만 든 다음:http://ws.Apache.org/axis/사이트 에서 Axis 설치 패 키 지 를 다운로드 합 니 다. 물론 다른 가방 에 도 의존 하고 있 습 니 다. 제 가 첨부 파일 에 사용 할 수 있 는 모든 패 키 지 를 올 려 서 여러분 께 편 의 를 드 립 니 다.
2. 그리고 wdd 파일 을 작성 합 니 다.
deploy.wsdd:
http://xml.apache.org/axis/wsdd/providers/java">
 
   
   
 


DOS 에서 디 렉 터 리 를% TOMCAT HOME% \ webapps \ axis \ \ WEB - INF 로 변환 합 니 다. 명령:
java -cp %AXISCLASSPATH% org.apache.axis.client.AdminClient deploy.wsdd
3. 두 번 째 단계 의 파일 을 직접 쓸 수 있 습 니 다. 코드 는 다음 과 같 습 니 다.
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="Login.jws" provider="java:RPC">   
     <parameter name="className" value="server.SayHello"/>
     <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 - INF 디 렉 터 리 에 웹. xml 과 함께 넣 으 면 WEB. XML 은 다운로드 한 axis 프로젝트 에서 직접 자신의 프로젝트 를 가 져 오 거나 추가 할 수 있 습 니 다.
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>

4. 서버 에서 제공 하 는 방법:
자바 코드 모음 집 코드
package server;

public class SayHello {
	public String getName(String name) {
		return "hello====>" + name;
	}
}

5. 클 라 이언 트 가 서버 인터페이스 에 접근 하여 데 이 터 를 얻 는 방법:
자바 코드 모음 집 코드
package client;

import org.apache.axis.client.Call;
import org.apache.axis.client.Service;

public class TestClient {

	public static void main(String[] args) throws Exception {

		//   service  URL     

		String endpoint = "http://127.0.0.1:8082/webservice/services/Login.jws";

		//       (service)  (call)     

		Service service = new Service();

		Call call = (Call) service.createCall();//   service  call       

		//   service  URL     

		call.setTargetEndpointAddress(new java.net.URL(endpoint));

		//    (processService) MyService.java            

		call.setOperationName("getName");

		// Object        ,   "This is Test!",  processService(String arg)     

		String ret = (String) call.invoke(new Object[] { "  " });

		System.out.println(ret);

	}

}

6: tomcat 시작, 먼저 접근http://127.0.0.1:8082/webservice/services표시 방법 이 있 는 지, 표시 가 있 는 지, 서버 에서 제공 하 는 인터페이스 가 성공 적 으로 접근 할 수 있 음 을 나타 낸다.
7: 그리고 로 컬 에서 클 라 이언 트 TestClient 를 뛰 면 결과 가 있 을 거 예요. 한번 해 보 세 요.
발췌:http://yangjizhong.iteye.com/blog/579511

좋은 웹페이지 즐겨찾기