I am started learning web services. And I have tried one sample web service example (fibonacci). At this stage, I have few queries to clarify.
As a service provider, I have to do the following things: (Pls correct me, if I am wrong)
1. Write the interface (with business methods) 2. Implement that interface.
3. Generate the WSDL file from the Interface using Java2WSDL tool. Here comes my first question: What this WSDL file contains?(I have seen this WSDL file, which is the XML file. That's what I know) What is the role of this wsdl file? Whether without Java2WSDL tool, we can generate manually?
4. Generate the Java Files from generated WSDL file using WSDL2Java Tool. Why we generating the Java files from WSDL xml file? Whether we can't do this wihout WSDL? That is generated WSDL xml file is having the interface details, I am guessing. Why can't from that interface, we can directly generated the rest of the java files like
How the client will know the service provided by the service provider?
And also, where are all we can use web services? Give some example application that suits web services? If so, why can't the EJB can be used for that same application?
Joined: Aug 19, 2005
Originally posted by Mark Tigerwood: What this WSDL file contains? What is the role of this wsdl file? We can generate manually?
The WSDL is the description of the Web Service Interface. You thought that you were defining the interface in step 1 - you only defined a Java representation of the web service interface, not the web service interface itself. There are no rules that state that either the web service or the web service clients have to be written in Java. They could be written in .NET, Perl, Python, Ruby, C, etc. To all non-Java participants the description of the interface in Java is useless. So the WSDL file is a text file, an XML file that describes the web service in the Web Services Description Language. The WSDL can be written manually though it is usually recommended that you use a WSDL aware XML-editor for that job. You can only really claim that you wrote the service interface first if you write the WSDL first.
Originally posted by Mark Tigerwood: Why we generating the Java files from WSDL xml file?
When you are writing a Java Web Service Client the Web service may not have any Java files for you because the service might not be implemented in Java. The WSDL is the file that "universally" describes the web service interface for anyone who wants to access it, regardless of the platform they are using.
Originally posted by Mark Tigerwood: How the client will know the service provided by the service provider?
Usually the provider will simply send the consumer the WSDL or the URL where the WSDL is located. The WSDL also includes the URL of the service. If the provider and consumer don't have any previous contact service registries like UDDI can be used.
Originally posted by Mark Tigerwood: If so, why can't the EJB can be used for that same application?
In general SOAP over HTTP can pass through a Firewall without problem. RMI as used by EJB cannot. Also ideally web services should be exchanging entire "documents", while with EJB you usually deal with smaller messages being sent between components - so it is also a matter of granularity.
So from the service provider side, they have to generate the WSDL xml file only(using some tolls like JAVA2WSDL).
The client will get this WSDL file and he will get the Java Files for this WSDL file(using some tools like WSDL2JAVA)
In case of fibonacci example, by above mentioned is true, then the client will have all the server side coding also.
For Example, everything mentined below, the cliet will get. FibonacciSoapBindingImpl.java Fibonacci.java FibonacciService.java FibonacciServiceLocator.java FibonacciSoapBindingSkeleton.java FibonacciSoapBindingStub.java deploy.wsdd undeploy.wsdd
So calling a method fib.calculateFibonacci(10)) is local to the client. That is, whether the client will call the calculateFibonacci(10)) in the server side or calculateFibonacci(10)) in the client side(since the client will going to get all those files (java files) mentioned above)?