웹 서비스의 실현
4704 단어 webservice
2. 그리고 wdd 파일 을 작성 합 니 다.
deploy.wsdd:
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
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
java가 클라이언트를 통해 서버 웹 서비스에 접근하는 방법본고는 자바가 클라이언트를 통해 서버 웹 서비스에 접근하는 방법을 실례로 설명한다.다음과 같이 여러분에게 참고할 수 있도록 공유합니다. 자바 관련 내용에 관심이 있는 더 많은 독자들은 본 사이트의 주제를 볼 수 있습...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.