내가 쓴 웹 서비스 using jax ws
3375 단어 webservice
package com.newtest.webservice;
import javax.jws.WebMethod;
import javax.jws.WebService;
@WebService
public class Hello {
private String message = new String("Hello, ");
public void Hello() {
}
@WebMethod
public String sayHello(String name) {
return message + name + ".";
}
@WebMethod
public int add(int i,int j){
System.out.println(i+"=+="+j);
return i+j;
}
@WebMethod
public int subtract(int i,int j){
System.out.println(i+"=-="+j);
return i-j;
}
@WebMethod
public int mul(int i,int j){
System.out.println(i+"=*="+j);
return i*j;
}
@WebMethod
public int divide(int i,int j){
System.out.println(i+"=/="+j);
return i/j;
}
}
wsgen -cp D:\workshop\New_test_webservice\build\classes com.newtest.webservice.Hello -wsdl -s wssrc -d build -r wsdl
package com.newtest.webservice;
import javax.xml.ws.Endpoint;
public class PublicService {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
Endpoint.publish("http://localhost:8080/New_test_webservice/HelloService", new Hello());
//Endpoint.publish("http://localhost:8808/New_test_webservice/HelloService", new Hello());
}
}
wsimport -s generate http://localhost:8808/HelloService?wsdl
package com.newtest.webservice;
import java.net.MalformedURLException;
import java.net.URL;
import javax.xml.namespace.QName;
import javax.xml.ws.Service;
public class WebserviceClient {
/**
* @param args
*/
public static void main(String[] args) {
URL wsdlURL = null;
try {
wsdlURL = new URL("http://localhost:8080/New_test_webservice/HelloService?wsdl");
} catch (MalformedURLException e) {
e.printStackTrace();
}
QName serviceQName = new QName("http://webservice.newtest.com/", "HelloService");
Service service = Service.create(wsdlURL, serviceQName);
Hello port = service.getPort(Hello.class);
//for(int i=0;i<2000;i++){
System.out.println(port.add(1, 3));
System.out.println(port.sayHello("rrr"));
//}
}
}
package com.newtest.webservice;
public class TestClient {
/**
* @param args
*/
public static void main(String[] args) {
HelloService server = new HelloService();
System.out.println(server.getHelloPort().add(1, 1));
}
}
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
java가 클라이언트를 통해 서버 웹 서비스에 접근하는 방법본고는 자바가 클라이언트를 통해 서버 웹 서비스에 접근하는 방법을 실례로 설명한다.다음과 같이 여러분에게 참고할 수 있도록 공유합니다. 자바 관련 내용에 관심이 있는 더 많은 독자들은 본 사이트의 주제를 볼 수 있습...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.