Hey there,
For some developers, especially those that are not familiar with Web Services, it might be difficult to figure out how to start off creating Web Services.
Today we are going to walk you through a simple tutorial, learning how to publish a Web Service, in your local machine, without a Web Server or an Application Server.
A Web Service is a set of functions that are exposed and published over a networking, allowing the separation of the function-service from its execution environment. This leads enterprise softwares to an easier integration approach of different software components, written in different languages and running in different operating system as well as decoupling those components.
Creating our Web Service
We are going to use the bottom-up model for designing a service, which means, we will not have a WSDL file first, but instead we are creating the classes, this model is also known as contract last, because de WSDL is created from the classes.
A developer using a bottom-up model writes implementing classes first (in some programming language), and then uses a WSDL generating tool to expose methods from these classes as a Web service. This is simpler to develop but may be harder to maintain if the original classes are subject to frequent change.
The web service will have only one operation, returning the sum of tho numbers. The class will be named AddService
-
Notice the annotations used in this class the @WebService indicates this class is a Web Service, also the method getResult has the annotation @WebMethod indicating it is service operation. An important observation is that every public method of the class AddService will be a service operation, even if we do not include the @WebMethod.
Let`s now publish this Web Service by adding one more class, if you want you can only add a new public static main method to the AddsService class, as in the bellow code of the ServicePublisher class:
If you are using Eclipse, just right click in the ServicePublish class, chose run as, and then Java Application, the Service will start running in the URL that you defined.
Once the service is running you can use a utility tool such as curl or you browser to get the .XSD, which is the Schema of th:
% curl http://localhost:8888/rs?xsd=1
In this example, the Endpoint runs indefinitely.
In the Second Part of this article, we are going to desigh a simple client to consume the Service.
For now, take a look at a bit more Information about the amazing class javax.xml.ws.Endpoint
- An Endpoint represents a Web Service endpoint
- An endpoint is either in a published or an unpublished state. The
- An
Learn more by reading the Official Javadocs at: http://docs.oracle.com/javaee/7/api/javax/xml/ws/Endpoint.html
For some developers, especially those that are not familiar with Web Services, it might be difficult to figure out how to start off creating Web Services.
Today we are going to walk you through a simple tutorial, learning how to publish a Web Service, in your local machine, without a Web Server or an Application Server.
A Web Service is a set of functions that are exposed and published over a networking, allowing the separation of the function-service from its execution environment. This leads enterprise softwares to an easier integration approach of different software components, written in different languages and running in different operating system as well as decoupling those components.
Creating our Web Service
We are going to use the bottom-up model for designing a service, which means, we will not have a WSDL file first, but instead we are creating the classes, this model is also known as contract last, because de WSDL is created from the classes.
A developer using a bottom-up model writes implementing classes first (in some programming language), and then uses a WSDL generating tool to expose methods from these classes as a Web service. This is simpler to develop but may be harder to maintain if the original classes are subject to frequent change.
The web service will have only one operation, returning the sum of tho numbers. The class will be named AddService
-
Notice the annotations used in this class the @WebService indicates this class is a Web Service, also the method getResult has the annotation @WebMethod indicating it is service operation. An important observation is that every public method of the class AddService will be a service operation, even if we do not include the @WebMethod.
Let`s now publish this Web Service by adding one more class, if you want you can only add a new public static main method to the AddsService class, as in the bellow code of the ServicePublisher class:
If you are using Eclipse, just right click in the ServicePublish class, chose run as, and then Java Application, the Service will start running in the URL that you defined.
Once the service is running you can use a utility tool such as curl or you browser to get the .XSD, which is the Schema of th:
% curl http://localhost:8888/rs?xsd=1
In this example, the Endpoint runs indefinitely.
In the Second Part of this article, we are going to desigh a simple client to consume the Service.
For now, take a look at a bit more Information about the amazing class javax.xml.ws.Endpoint
- An Endpoint represents a Web Service endpoint
- An endpoint is either in a published or an unpublished state. The
publish
methods can be used to start publishing an endpoint, at which point it starts accepting incoming requests. Conversely, the stop
method can be used to stop accepting incoming requests and take the endpoint down. Once stopped, an endpoint cannot be published again.- An
Executor
may be set on the endpoint in order to gain better control over the threads used to dispatch incoming requests. For instance, thread pooling with certain parameters can be enabled by creating a ThreadPoolExecutor
and registering it with the endpoint.Learn more by reading the Official Javadocs at: http://docs.oracle.com/javaee/7/api/javax/xml/ws/Endpoint.html
such a great article... thanks
ReplyDelete