WebService Link
Steps for WebService:In Netbeans create a new project as new webapplication
- New Web Application set source level to 1.6JDK.
- RightClick to project to new->webservice.
- Give webservice Name and package.
- Open webservice folder right click in the webservice (public class Test {) ->click add operation
- define webmethod add and web variables i and j.
- Properties -> Run->relative url “/CalculatorWS?Tester” for Tomcat
- Deploy webservice.
HelloWebService
package org.me.calculator;
import javax.jws.WebMethod;
import javax.jws.WebParam;
import javax.jws.WebService;
/**
*
* @author harshals
*/
@WebService()
public class CalculatorWS {
/**
* Web
service operation
*/
@WebMethod
public int
add(@WebParam(name = "i") int i, @WebParam(name = "j") int
j) {
// TODO implement operation
int k=i+j;
return k;
}
Steps to create the WebServiceClient.
1.
New Java Client
2.
Right JavaClient -> WebService Client
3.
Project browse to Webservice or provide the wsdl
location “ http://localhost:8084/ HelloWebservice/CalculatorWS? wsdl”
4.
Right click in main ->Webservice Client resources.
5.
Run Project
6.
Voila webservice is ready.
Main.java
package hellojavaclient;
/**
*
* @author harshals
*/
public class Main {
/** Creates a new
instance of Main */
public Main() {
}
/**
* @param
args the command line arguments
*/
public static
void main(String[] args) {
try { // Call Web Service Operation
org.me.calculator.client. CalculatorWSService service = new
org.me.calculator.client. CalculatorWSService();
org.me.calculator.client. CalculatorWS port = service.getCalculatorWSPort();
// TODO initialize WS operation arguments here
int i = 0;
int j = 0;
// TODO process result here
int result = port.add(i, j);
System.out.println("Result = "+result);
} catch (Exception ex) {
// TODO handle custom exceptions here
}
// TODO code application logic here
}
}
No comments:
Post a Comment