8 Replies Latest reply on Jul 23, 2012 6:10 AM by ramp

    struggling with web services

    949273
      I want to create a simple web service using SOAP. I've googled around, but tutorials are either too simple (only primitives passed to web service, no user-defined instance) or incomplete. If possible, I wish to use Java built-in libs only, so no axis, cxf, or any other of that. After I've understood the basics, then I'll poke around axis and cxf myself. Right now, I have simple web service like so:
      import javax.jws.WebMethod;
      import javax.jws.WebService;
       
      @WebService
      public class MyService{
       
           @WebMethod(operationName="doService")
           public String doService(String name) {
                return "Hello " + name;
           }
       
      }
      As you can see, the doService method takes a String. What I need is, the client will send an XML file like so:
      <Country>
          <name>USA</name>
          <currency>USD</currency>
          <states>
              <state>Florida</state>
              <state>Texas</state>
          <states>
      </Country>
      
      <Country>
          <name>Australia</name>
          <currency>AUD</currency>
          <states>
              <state>ACT</state>
              <state>SA</state>
          </states>
      </Country>
      so I'm thinking in the server side, I must prepare class representation of this input from client like so:
      public class Country{
          private String name;
          private String currency;
          private List<State> states;
      
          //getter and setter
      
      }
      public class State{
          private String name;
      
          //getter and setter
      }
      how does the doService look like? like this?
           @WebMethod(operationName="doService")
           public ???? doService(Country country) {
                //do something with country
           }
      the web service is expected to return country's rating based on currency strength and number of states. As you can all see, the doService has undetermined return type, because I don't know the return type. XML? filestream? String? the client is expecting the web service to give object to conform the definition on client side:
      public class Ranking{
          private String countryName;
          private double countryScore;
          //setter and getter
      }
      Can anybody help me? thanks a lot. And please remember the customer asked specifically to implement using SOAP (not REST)

      Edited by: 946270 on Jul 13, 2012 2:53 AM