Web Services: Creating and Deploying a Java Web Service

Home

News: Web Services: Creating and Deploying a Java Web Service

  1. I will show you how to create your own simple java web service.

    Getting Started

    First of all, we need to set up a server to host the web service. I’m using Glassfish 4.0, which allows you to host a local server on your own machine. You can install it yourself and point your IDE in the direction of it’s installation folder. Alternatively, with NetBeans you can download and install Glassfish (amongst others) when you create the project.

    Now we need to create the project, in NetBeans:

    1. Go to File>New Project.
    2. Select the Java Web category and in the adjacent window select Web Application.
    3. Name your project and then press next.
    4. Select which server you want to use e.g. GlassFish. If no servers are available click Add and select Glassfish, press next and download the server.
    5. Press finish.
    6. You may get a page created called index.html, you can close it as it’s not needed.
    Creating a Web Service

    in your projects window, right click the Source Packages folder, go to New and from the list Select Java Class. You can choose Web Service and it will create a fully generated web service class with some example methods....

    Read the rest of the article at Java PDF Blog

  2. Getting Started

    First of all, we need to set up a server to host the web service.

    Need not be the case.

    This is a misconception. You can use the Jetty server embedded with Java itself. For example add the following main method to the SimpleWebService.java file and execute. Thats all. Server runs at 127.0.0.1 with port 9009. wsdl is available at http://127.0.0.1:9009/SimpleWebService?wsdl.

        public static void main(String[] args) {

            System.out.println("Starting Server");

            SimpleWebService implementor = new SimpleWebService();

            String address = "http://127.0.0.1:9009/SimpleWebService";

            Endpoint.publish(address, implementor);

            System.out.println("Server stated at Endpoint : " + address);

    }

     

    Thanks.

    Siva