我写的webservice using jax ws

 

 

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));
		   
	}

}

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

你可能感兴趣的:(webservice)