JWS-based WebService project

Source: Internet
Author: User
Tags wsdl

JWS-based WebService Project 1, server-side building

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-based WebService project

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.