8 Replies Latest reply: Jul 23, 2012 1:10 AM by ramp RSS

    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
        • 1. Re: struggling with web services
          gimbal2
          You might want to check out the Metro user manual.

          http://metro.java.net/discover/

          (Metro is the "built in lib" you're talking about - it is the reference implementation of the JAX-WS API). In any case nobody is going to explain to you how this stuff works, it is not a subject that you can fit in a forum post. Whole books have been written about it. Good sources of information too, books. Not as fragmented as the web.
          • 2. Re: struggling with web services
            949273
            Does this come with Java 6? or I should upgrade to Java 7? thanks for the reply
            I just glanced a bit and read that I need to download Metro binary. I thought you said it's built in Java lib?
            care to share the title of the books you mentioned?

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

            Edited by: 946270 on Jul 13, 2012 6:56 AM
            • 3. Re: struggling with web services
              gimbal2
              Yes its embedded in the JDK, but the version that comes with Java 6 is of course old (metro 1.1) since Java 6 itself is quite old and nearly end of service.

              Upgrading Java is an option, but you can also bundle the latest version of Metro with your application like you would any other API. Or if this is a JEE application there will already be a webservices stack provided by your application server and you don't need to deploy anything with your application.
              • 4. Re: struggling with web services
                949273
                what about hte books you mentioned earlier? any title so I can look into them? thanks
                • 5. Re: struggling with web services
                  gimbal2
                  Amazon user reviews.
                  • 6. Re: struggling with web services
                    949273
                    amazon user reviews? I've searched in amazon with the keyword metro, but none of them were about java web service. any help?
                    • 7. Re: struggling with web services
                      gimbal2
                      JAX-WS is the API and that's what you want to find a book about. You couldn't have been looking for information for very long if you don't even know the bare basics of the thing you are trying to use. On that note, I'll leave you to your own devices. Good luck with your research which I'm sure you will now dive into with full enthusiasm.
                      • 8. Re: struggling with web services
                        ramp
                        I have found this - http://www.omii.ac.uk/wiki/JaxWsTutorial very helpful for a jump start to JAX-WS. You should have prior knowledge of Webservices, SOAP, WSDL etc