How does a webservice work
Asked Answered
M

3

6

I am new to webservices and i want to implement webservices by using java in my eclipse project.

So can anyone tel me how to implement and creating a project please

Thanks

Munificent answered 28/12, 2010 at 6:41 Comment(2)
Check out softwaresummit.com/2005/speakers/RymanDevWSwithEclipse.pdfLieberman
Check the webservice section hereCauseway
G
8

As defined by W3C web service is a software system to support interoperable machine-to-machine interaction over a network. More elaborately a system consumes service from other software system.

Web services has two major classes:

  • REST compliant
  • arbitrary web service

To implement web service one need to choose one category on the basis of his/her requirement. Java has bunch APIS to implement web services on both category.

Requirements before implementing web service is :

  • XML
  • WSDL (web service description language)
  • SOAP protocol etc

REST based is bit easy to implement compare to other category. So it's better to start with REST complaint web services.

How web service works :

WS works as request-response paradigm , there is an entity which will request for some service to it's specific counterpart namely service provider entity. Upon request, service provider will respond with a response message. So there are two message involved hear one Request message (XML)and one Response message (XML). There are bunch of ways to achieve these. Detail can be found at web service architecture

Beginner can start with JERSEY jsr311 standard reference implementation to build RESTful web services.

Example (jersey specific):

Step One : Creating root resources

// The Java class will be hosted at the URI path "/helloworld"
   @Path("/helloworld")
   public class HelloWorldResource {

       @GET 
       @Produces("text/plain")
      public String getClichedMessage() {
          return "Hello World";
      }
  }

Step Two : Deploying

public class Main {

  private static URI getBaseURI() {
      return UriBuilder.fromUri("http://localhost/").port(8080).build();
  }

  public static final URI BASE_URI = getBaseURI();

  protected static HttpServer startServer() throws IOException {
      System.out.println("Starting ...");
      ResourceConfig resourceConfig = new PackagesResourceConfig("com.sun.jersey.samples.helloworld.resources");
      return GrizzlyServerFactory.createHttpServer(BASE_URI, resourceConfig);
  }

  public static void main(String[] args) throws IOException {
      HttpServer httpServer = startServer();
      System.out.println(String.format("Jersey app started with WADL available at "
              + "%sapplication.wadl\nTry out %shelloworld\nHit enter to stop it...",
              BASE_URI, BASE_URI));
      System.in.read();
      httpServer.stop();
  }    

}

REST REFERENCE - by Roy T . Fielding

Georgiannageorgianne answered 19/5, 2012 at 19:10 Comment(0)
Y
2

Webservice is some program interface, which uses SOAP protocol for communication. Using soap, you can communicate with any program, no matter on which language it is written.

SOAP is an XML-based communication protocol and encoding format for inter-application communication. Originally conceived by Microsoft and Userland software, it has evolved through several generations; the current spec is version, SOAP 1.2, though version 1.1 is more widespread. The W3C's XML Protocol working group is in charge of the specification. SOAP is widely viewed as the backbone to a new generation of cross-platform cross-language distributed computing applications, termed Web Services.

Here is some examples:

Java web services tutorial

Axis - One of ASF implementations

CXF (Previously known as "XFire")

Yasmineyasu answered 28/12, 2010 at 7:10 Comment(3)
Thanks for replying vadeg, Can u give me some sample project of webservice so that i can still more clearly understand it... pleaseMunificent
WebServices do not HAVE to use SOAP. SOAP is simply one method.Poky
As @Vadeq said there are at the moment two main frameworks for web services in Java - Apache Axis and Apache CXF. Both of them have their fans, however I prefer to use CXF (you can find some comparison of them for example in this question). If you decide to use CXF, here you can find some information (with code examples) on publishing web services and creating web services clients. There are also lots of other tutorials which should be easy to google.Plasmagel
A
0

One of the easiest and best ways is to develop webservice using Apache Axis. Eclipse SOA toolkit supports Axis.

More information regarding sample project can be found here!

http://onjava.com/pub/a/onjava/2002/06/05/axis.html

Arrestment answered 28/12, 2010 at 10:9 Comment(2)
This is very old article (2002) and is not current. The concepts of webservices has not changed much but implementation technologies has changed a lot.Causeway
I have given, this link keeping in view that, it might would give a breif idea.Arrestment

© 2022 - 2024 — McMap. All rights reserved.