1, server-side establishment
1.1. Create an interface
[Java] View plaincopy
@WebService
Public interface Iwebservice {
int add (int a, int b);
int subtract (int a, int b);
}
1.2. Create an implementation class
[Java] View plaincopy
@javax. Jws.webservice (endpointinterface = "Org.gwr.service.IWebService")
public class WebService implements Iwebservice {
@Override
public int Add (int a, int b) {
System.out.println (A + "+" + B + "=" + (A + b));
return a + B;
}
@Override
public int subtract (int a, int b) {
System.out.println (A + "-" + B + "=" + (a));
return a-B;
}
}
1.3. Deployment Services
[Java] View plaincopy
public class Releaseservice {
public static void Main (string[] args) {
String address = "Http://localhost:8888/ns";
Endpoint.publish (Address, New WebService ());
}
}
2, the client set up
Call WebService
[Java] View plaincopy
public class Callservice {
public static void Main (string[] args) {
Create a URL to access the WSDL service address
try {
URL url = new URL ("http://localhost:8888/ns?wsdl");
Specify the specific information of the service through QName
QName sname = new QName ("http://service.gwr.org/",
"Webserviceservice");
Create a service
Service service = service.create (URL, sname);
Implementing interfaces
Iwebservice ms = Service.getport (iwebservice.class);
System.out.println (Ms.add (12, 33));
} catch (Malformedurlexception e) {
E.printstacktrace ();
}
}
}
JWS WebService Code