facebook

Translation of .NET Web Service to JAX-WS on Websphere 6.1

  1. MyEclipse IDE
  2.  > 
  3. WebSphere Development
Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #299254 Reply

    Heartsbane
    Member

    I’m looking to migrate an existing .NET web service (VB .NET / MS SQL Server 2005) to a JAX-WS web service with a DB2 database.

    I’ve successfully migrated the SQL Server 2005 database/data to DB2. I’ve also installed WebSphere App Server 6.1 with Web Services Feature Pack and MyEclipse Blue.

    I’ve been through the tutorial on JAX-WS web services for WebSphere (http://www.myeclipseide.com/documentation/quickstarts/blueedition/blue_jaxws/) and have successfully developed/deployed the “calculator” class and tested it using a SOAP client.

    However, I haven’t been able to figure out how to connect the database to my JAX-WS project and execute SQL statements (select, insert, update) against the DB2 database. Everything I try seems to result in more questions / options that I don’t understand. I’m fairly new to IBM Websphere / Java development.

    Does anyone know of any links/tutorials that specifically address how to setup a JAX-WS web service with a DB2 database back-end? The DB2 integration is quite simple — just basic SQL SELECT, INSERT, UPDATE statements. All I need to do is take appropriate parameters into the web service methods, execute the SQL, and return a recordset back in the SOAP response. But I’ve yet to find any kind of tutorial or information on how to do this and clicking around blindly has only gotten me more confused.

    Any help is appreciated!

    #299427 Reply

    Brian Fernandes
    Moderator

    Heartsbane,

    Two parts to your question –

    1) Converting records from your DB2 database to Java and vice versa.
    You can do this using straight JDBC if your queries are really simple and have a small number of objects to deal with.

    If you have many objects and more complex relationships and queries (and a system that could potentially grown in time), you could consider using JPA to handle this conversion for you.

    2) Sending/receiving Java objects “on the wire” to/from the web service
    JAX-WS uses JAXB2 for data binding by default, you need to annotate your Java objects (could be the POJOs that MyEclipse generates for you during JPA reverse engineering process).

    Please have a look at our JAX-WS tutorials and let us know if you require further assistance. More info on JAX-WS can be found here: https://jax-ws.dev.java.net/

    #299429 Reply

    Heartsbane
    Member

    Brian – thanks for the reply. When you say I need to “annotate your Java objects” for JAXB2 can you explain how that is done? I did JPA reverse engineering and generated POJOs for my DB2 database, but I’m not sure what you mean by annotating them to work with JAXB2.

    The only JAX-WS tutorial I found was the one that created the simply calculator class (add, subtract, etc.). This really helped me to understand JAX-WS web services and how to create/deploy them to Websphere from MyEclipse Blue. However, there was nothing in that tuturial discussing how to use JAX-WS web services to call DB2 (or other database) SQL statements and return the results. Are there other JAX-WS tutorials that show interaction with databases that I’m not aware of? If so, can you provide me with a link?

    Thanks!

    #299431 Reply

    Brian Fernandes
    Moderator

    However, there was nothing in that tuturial discussing how to use JAX-WS web services to call DB2 (or other database) SQL statements and return the results.

    Unfortunately, there is no shortcut here that will bridge your database with the webservice directly. It will be Web service <> (using JAXB2) Java <> (using SQL directly or JPA) DB2.

    What you could try to do is build a class like the calculator class which contains the methods you wish to expose, this class will in turn call into your JPA objects to return the data requested. e.g.

    public class MyCustomerService {
      public String getCustomerName(int custId) {
        CustomerDAO dao = new CustomerDAO();
        Customer customer = dao.findById(custId);
        return customer.getName();
      }
    
     public Customer getCustomer(int custId) {
        CustomerDAO dao = new CustomerDAO();
        return dao.findById(custId);
      }
    }

    I would pass the MyCustomerService class to the bottom up wizard. Your Customer object should automatically be serialized to/from XML by wrapper classes generated by the bottom up process – see the .apt-generated folder in your project – you should see a class for each service request and response. Observe that these classes have JAXB2 annotations (e.g. @XmlRootElement). One of the fields in this wrapper class would be your Customer object (for the getCustomer method in MyCustomerService) – this will be serialized to XML using JAXB2 defaults.

    You may be happy enough with the default mapping (I recommend giving this a shot first before going further), but if not – you will need to add JAXB2 annotations manually to the customer class to change the way in which it is mapped to / from XML. See the marshalling and unmarshalling sections at this location: https://jaxb.dev.java.net/guide/

    Hope this helps.

Viewing 4 posts - 1 through 4 (of 4 total)
Reply To: Translation of .NET Web Service to JAX-WS on Websphere 6.1

You must be logged in to post in the forum log in