Announcement Announcement Module
No announcement yet.
Using Spring WS client - how to call a WS operation? Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Using Spring WS client - how to call a WS operation?


    I would like to use the Spring WS client, and started with the example from the documentation:

    private static final String MESSAGE = "<message xmlns=\"\">Hello Web Service World</message>";
    private final WebServiceTemplate webServiceTemplate = new WebServiceTemplate();
    public void setDefaultUri(String defaultUri) {
    // send to the configured default URI
    public void simpleSendAndReceive() {
    	StreamSource source = new StreamSource(new StringReader(MESSAGE));
    	StreamResult result = new StreamResult(System.out);
    	webServiceTemplate.sendSourceAndReceiveToResult(source, result);
    However, I do not quite understand how to call a special WebService operation. As an example, I have to call this Webservice:


    and the Webservice-operations available are "createExample" and "updateExample".

    How can I make sure, the correct operation is called on the remote Webservice, is it all a matter of the correct XML message? How would the "MESSAGE" constant above look like to call "createExample" in my case?

    I really appreciate any help you can offer

    Thanks a lot!

  • #2
    Is this question too basic to get noticed? ;-)


    • #3
      I have the same question. Did you ever get this resolved?


      • #4
        Not yet, I think the manual is not very clear about this. Especially for beginners, this information should be added.

        Meanwhile, I'm still looking for an answer..


        • #5
          I may have a response for you from my 10 minutes Spring-WS try.

          Based on your sample, you can prepare the following message :

          final String createMessage = "<createExample xmlns=\"\"></createExample>"
          final String updateMessage = "<updateExample xmlns=\"\"></updateExample>"
          Then call the request service

          public void simpleSendAndReceive() {
                  StreamSource source;
          	StreamResult result = new StreamResult(System.out);
                  // Call create Operation
          	source = new StreamSource(new StringReader(createMessage));
          	webServiceTemplate.sendSourceAndReceiveToResult(source, result);
                  // Call update Operation
                  source = new StreamSource(new StringReader(updateMessage));
          	webServiceTemplate.sendSourceAndReceiveToResult(source, result);
          For the moment as long as there is no args, I'm able to invoke operation by this way... But I'm trying to invoke operation with one args and I'm not able to do so (always receiving a null value)


          • #6
            In fact, the more advanced sample I find in the doc reference is :

            Chapter 3. Writing Contract-First Web Services
            3.2. Messages

            where you can find a HolidayRequest Message.




            • #7
              In order to invoke operations with parameters, you just have to add the correct argument with the correct namespace :

              final String createMessage = "<createExample xmlns=\"\">
              final String updateMessage = "<updateExample xmlns=\"\">
              Thanks to Spring-WS, Dynamic WebService invocation becomes simple.