Simple web services in Java applications - java

I am new to web service and WSDL. I have a MySQL database stored in a server and I need to create a very simple web service that allows third party Java applications to input an integer (say 'membership number') and receive a string (say 'member name'). This should be done with WSDL.
Can someone please tell me what files do I need? A WSDL file, a schema file? Do I need a Java class stored in the server responsible to communicate with the database?
I am pretty lost, I would be thankful if you could give me some suggestion

As the simplest form of webservice is you can continue with JAX-WS, upon deployment of appilication it will publish a WSDL file and you can use this WSDL to communicate it from client

JAX-WS is the simplest way to convert an existing method into a web service endpoint, with a few annotations, and the simple web server in the standard Java 6 JRE. It can autogenerate the WSDL too.
This tutorial covers the essentials for getting started: http://java.dzone.com/articles/jax-ws-hello-world
I have found this to be a very robust technology.

Using the SOAP Webservices can get pretty messy. Unless you are forced, I would recommend you use REST for webservices, it is much less complex than SOAP. You can find a good REST tutorial here.
If on the other hand you must use SOAP, you could strat by taking a look here.

Related

Consume .NET web services in Java

I have created .NET web services. I want to run it on a remote server and have the Java Applications (clients) contact the server for data. How should I implement the Server such that the Clients can make use of the org.apache.xmlrpc.client.XmlRpcClient package?
I just want the clients to generate a request for data and does not want to have any other dependencies.
Here is a good material on using eclipse for this purpose: http://wso2.org/library/tutorials/creating-web-service-client-3-steps-using-eclipse
Thanks.
Although both are rightfully called "web services" the SOAP based web services usually created in .net are incompatible with web services following the older XML-RPC standard.
In my opinion you can follow 2 routes to solve your problem:
either you go the SOAP route under Java, one of the most common API's for that purpose would be jax-ws - some excellent pointers to tutorials here, in Pascal Thivent's answer
or you transform your .net webservices to XMl-RPC by using xml-rpc.net
Both routes have advantages and disadvantages, it's hard to make that choice for you without knowing more about your project. A priori choosing the SOAP route might look "safer" as there the entire communication will be based on standard components.
If you have the Web Services on the .NET side, you must have a Web Service Description Language (WSDL) (if you are not talking about REST), you can easily create the client classes to consume this Web Service using an IDE, check this link here: http://netbeans.org/kb/docs/websvc/client.html
If you are using Eclipse I suggest you this tutorial to build a simple WS client.
You can adapt this example application to your real needs.
NOTE the example uses an old version of Eclipse, but the wizard is very similar also in newer versions.

How To Use WSDL Url

I wrote a java web service on Netbeans 6.9.1 and deployed on GlassFish 3.0.1
I have a wsdl url like this "http://localhost:8080/web2/service2Service?wsdl".
How can I use this url to access this web service from another java application.
Thanks
You need to generate some Java that represents the client's view of the Web Service and then invoke that Java. Here's an article which explains some of the detail.
Generating client from WSDL in Eclipse
The general idea is that you generate some Java classes from the WSDL. Those classes act as a proxy for the service you want to call. Your java invokes methods on the proxy objects, the generated code creates the appropriate SOAP messages, sends the HTTP request, interprets the response and your code just sees a Java result.
I just use the tooling built into Eclipse, but you will also find other suitable generators, for example in Apache's Axis
1º U must save the content in a "myWebServices.wsdl" file
2º Run your Wsdl converter, all compilers have one of this, normally the name is WDSL.EXE
This process will create a new file with NameSpace or Package with the definitions of webservices built in.
3º Then imports this package or built a library.
Develop web service Client in second application.
You can use Netbeans to create web service client by giving your wsdl url
The document at this url is the actual wsdl (a description of the actual webservice, written in WebService Definfition Language).
The description includes information about the services url, the protocol(s), the method names and and data objects. Your application will use that information to call the remote methods of that service.
The protocol may or may not be SOAP, and without knowing the webservice details, it's quite impossible to recommend a toolset or methodology to use the webservice, there is no general approach. In most cases we see SOAP, for those services I recomment soapUI as a general tool to use and test SOAP based webservices and apache axis to implement java based service consumers.

Creating a Java based web service

I have a very basic Java based web service requirement. Requirement is very simple, pass some String parameters, save them to database and generate a response ("success", "failed"). There is also a case where I need to return simple XML representation (SOAP message) of a simple Object:
<person>
<name>the name</name>
<address>the name</address>
......
</person>
Our current environment is Windows, Apache Tomcat 5, SQL Server.
I'm new to web services so I'm trying to figure out what technologies I could use to make this work. For example:
Do I really need Apache Axis 2 to implement this or would it be overkill?
I saw a tutorial online where all that was needed to create web service was Eclipse, Lomboz plugin for Eclipse and Apache Tomcat. Will I still need Apache Axis2 if I take this route?
Is it possible for Tomcat to process web service requests messages or do I need third party libraries?
I guess I'm looking for the easiest way to implement this. Thank you.
Do you actually need SOAP support? If you do, Axis is probably your best bet. Otherwise, I'd take a look at Jersey.
If it will be as simple as you have mentioned, why don't you look at RESTful Web Services? You can specify your resource calls through a GET, POST, DELETE or PUT HTTP methods.
There's a blog tutorial on how to achieve this. It also shows you how you can return JSON strings/XML (depending on what you want).
A web framework would make this much easier (and actually maintainable), but you could just write a raw servlet to handle requests. You'll want to use an XML object serialization method, though, or at the very least an xml parsing library.
I think you would need axis for this one. But I'll advice you to look at Apache CXF, if in future you will need more support with web service apps. CXF just like axis2 is an implimentation of jax-ws but with an advantage of supporting jax-rs (rest). This means you can expose both REST and SOAP web service interfaces.

Remote Web Services

I am new to web services. I have a requirement in my project. I have to consume the web services of our vendor in my project. All he has shared with me is a WSDL file and a document about the description of the the different operations.
Question:-
1: What do I need to do consume these web services in my java project? I have been advised to use axis2, eclipse with tomcat6.
2: Do I need to ask for some other files/information from WS vendor OR wsdl file is enough to consume these web services?
3: Do I need to write a java WS client (using axis2 plugin) or another webservice which will talk to vendor web service?
Please suggest the best possible way.
I am sorry if the question sounds like a naive..
Axis is a solid choice for such application.
You need to generate an axis client based on the provided WSDL. Then you import the generated client and use it's methods. You can see the details of this process here (read whole page or starting from the linked section): http://ws.apache.org/axis2/1_0/userguide3.html#Writing_Web_Service_Clients_using_Code_Generation_with_Data_Binding_Support
You could also need some entry-point (WebService URL).
You need to generate a client, not a webservice. See point 1.
Don't use Axis if you need ambient authentication in a Windows environment. I went down that path and ended up going with Apache CXF - which seems better to me anyhow.
You can use SOAP UI to test the web service. It'll read the WSDL, let you create requests by filling in values, and display the response that you get back. It might help you get a better understanding of what the service does before you start writing your classes.
You don't need to create a new web service in order to consume a web service, you need to write a web service client.
Similar question to this one:
Steps in creating a web service using Axis2 - The client code
All the standard web frameworks have a command (normally called wsdl2java) that will read the WSDL and then generate a java based client object.
I can recommend Axis2, but another popular choice is CXF

best way to communicate between .net and java

I have a .net application which needs to expose a service consumed by a java client. The service can't be public. There should be some authentication mechanism for the client. What is the best way to do this? I'm new to web services and am confused by all the soap, wsdl etc. and have also heard a lot that it'll be a pain to get the two to communicate. Your thoughts?
Web Services are the one of the best approaches for interoperability over WEB. it's not that much difficult to create and use. It's as simple as Connecting to different databases and writing XML parsing in your code.
There are so many ways doing authentication. If you are using the IIS for deploying .net web services, then You can use Windows Authentication, Forms Authentication. These 2 are out of the box features of IIS. You can implement your custom authentication also. There are few compatible cryptography algorithms also for encrypting your data.
Without web services, it's very difficult to establish communication between Java ad .net.
You can give a try for JSON also. But i am not sure.
Hey check this video which gives you details. http://skillsmatter.com/podcast/java-jee/consuming-a-dot-net-web-service-using-java
I'd go for a simple REST interface using something like Jersey on the Java side, and a .Net JSON library to parse the data I consume.

Categories