Results 1 to 8 of 8
  1. #1
    BobswYourUcle is offline Member
    Join Date
    Mar 2011
    Posts
    23
    Rep Power
    0

    Default Create a basic standalone web service

    Hello,
    I am trying to use Apache Axis2 to create a basic web service that adds 2 numbers together and returns the result. As a reference I have used both:
    Apache Axis2 - Writing Web Services Using Axis2's Primary APIs
    Tutorial 1: Creating Web Services in Eclipse (Bottom Up) [Indigo] | Christos Tranoris

    I can get my web service up and running, I also created a client that calls it which also works. What I want to do now is change the code so that it "lives" in the right place.

    After reading the above 2 links it apears to me that no interface is required and that I can simply create a class MyService.java and within it have the method
    Java Code:
    public int AddNumber(int first, int second){
        return first + second;
    }
    Is that really all I need to do? or should the MyService.Java be an interface that calls the class AddNumbers()?

    While I have my example working I would like to make sure that it is correct, please advise me.

    Thanks agiin

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,305
    Rep Power
    25

    Default Re: Create a basic standalone web service

    Your post is leaving out a lot of details about your project. Maybe someone will go read the links and figure out what you are trying to do and maybe not. The more information and explanations you give about the problem you are having, the more likely you'll get help.
    You have posted the code for a very simple method. What is the context for this method? What class is it in, how is it called, etc?

  3. #3
    BobswYourUcle is offline Member
    Join Date
    Mar 2011
    Posts
    23
    Rep Power
    0

    Default Re: Create a basic standalone web service

    Ok, sorry you are right. I am just not sure how to ask my question. I do not need help with code it is more about the proper way to create a web service and where to put all of the code. So far I have created a standalone webservice using Axis2. I know the methods do not do much, but I still want them to built as if they did so that I fully understand how it should be done.

    To create the web service I have:
    Created a new project
    Added a new package
    Within the package added a single class called MyService.java, which class contains the method AddNumber(int first, int second) and the method SayHello(String name).

    That all works. My questions are:
    Is that correct (just a single class MyService that returns the results of either method)?
    Or
    Should MyService.java be an interface to a class Numbers and a class Hello which then contain the methods?
    Or
    Should I have the class MyService which contains the method AddNumber(int first, int second) call another class that "does the work"
    Lastly
    Am I correct in thinking that an interface is not really needed as I have a *.WSDL that defines the methods?

    I hope that is clearer. I really want to make sure that what I do is correct. I have attached a screen shot which has my webservice layed out two diferent ways, is either of them correct? Or do I need to create an interface? I hope this explains what I am asking better.

    Create a basic standalone web service-2-examples.gif

    Thanks again

  4. #4
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,305
    Rep Power
    25

    Default Re: Create a basic standalone web service

    I'm not sure this is the correct place in the forum for your question.
    I personally don't know what you mean by a "web service". A lot of what you are doing sounds like configuring a server vs beginning programming.

  5. #5
    BobswYourUcle is offline Member
    Join Date
    Mar 2011
    Posts
    23
    Rep Power
    0

    Default Re: Create a basic standalone web service

    Thanks,

    This is a dev question, not server. By Web Service I mean that this project when deployed can be accessed via http and will use xml, it will be consumed by a different application which will use whatever data is returened in this case either the sum of 2 numbers or the name. I am just trying to figure out where in my project the code should be and if I should be using an interface class to access the methods.

    For instance in the above attachment I have the same class writen 2 different ways. I am trying to figure out the best way to write my code. The first example has a single class with 2 methods, thoes methods contain the "business logic" so nothing is seperated.
    The bottom half of the attachment has it written with the same 2 methods but instead of containg the business logic it seperates it into 2 classes Hello.java and Numbers.java.

    Is either way better?
    Are both bad?
    Should there be an interface?

    Sorry, I know I am not being clear but I cant think of a better way to ask this.

    Thanks again

  6. #6
    clydedoris is offline Member
    Join Date
    Feb 2010
    Posts
    80
    Rep Power
    0

    Default Re: Create a basic standalone web service

    What you're really trying to figure out is the best way of implementin the program logic from a systems analyst's (program designer's) point of view, and you already know that the code will work whichever approach you're going to use, correct?

    Well, IMO, the program is really simple for you to be thinking that much. I think the code you presented should be fine.
    [why are you annoyed with my sig?]

  7. #7
    BobswYourUcle is offline Member
    Join Date
    Mar 2011
    Posts
    23
    Rep Power
    0

    Default Re: Create a basic standalone web service

    Yes exactly! and thanks, for clearing it up for me.

    While I understand what I have is a simple example, what if it were more complicated? Would this still do?

    What about an interface, for some reason I feel like i am missing the signitures of the web service methods, or is that taken care of with the WSDL?

    Thanks again

  8. #8
    Tolls is online now Moderator
    Join Date
    Apr 2009
    Posts
    11,800
    Rep Power
    19

    Default Re: Create a basic standalone web service

    For the web service itself you should really start with the WSDL.
    When that's done, you can then generate the server code (and client code later on)...and that will include a class into which you can either stick the above code (as it's so simple), or call the above code...which is what you'd normally do really. The web service code is just there to get into your "business layer", ie the code where all the work is done.

Similar Threads

  1. How to create SPML Web Service
    By DeathSpiral in forum Advanced Java
    Replies: 3
    Last Post: 07-07-2012, 07:48 AM
  2. Apache Axis Web Service Create Error
    By richierich in forum Advanced Java
    Replies: 0
    Last Post: 04-19-2011, 07:58 AM
  3. Create Windows Service From Jar
    By appdevman in forum Advanced Java
    Replies: 1
    Last Post: 06-24-2010, 02:17 AM
  4. Create Your First Web Service in MyEclipse
    By sjx19871109 in forum Eclipse
    Replies: 1
    Last Post: 05-04-2010, 09:18 PM
  5. How to create datasource for standalone application using JPA
    By identita in forum Enterprise JavaBeans (EJB)
    Replies: 0
    Last Post: 12-03-2009, 01:04 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •