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

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

    Hello,

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

    Code:
    private static final String MESSAGE = "<message xmlns=\"http://tempuri.org\">Hello Web Service World</message>";
    
    private final WebServiceTemplate webServiceTemplate = new WebServiceTemplate();
    
    public void setDefaultUri(String defaultUri) {
    	webServiceTemplate.setDefaultUri(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:

    "http://example.org/exampleWebservice"

    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? ;-)

    Comment


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

      Comment


      • #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..

        Comment


        • #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 :

          Code:
          final String createMessage = "<createExample xmlns=\"http://yourns.org\"></createExample>"
          final String updateMessage = "<updateExample xmlns=\"http://yourns.org\"></updateExample>"
          Then call the request service

          Code:
          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)

          Comment


          • #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.

            HTH

            Steph

            Comment


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

              Code:
              final String createMessage = "<createExample xmlns=\"http://yourns.org\">
                                                          <myText>MySample</myText>
                                                      </createExample>"
              final String updateMessage = "<updateExample xmlns=\"http://yourns.org\">
                                                           <id>1</id>
                                                           <myTest>MyUpdatedSample</myText>
                                                       </updateExample>"
              Thanks to Spring-WS, Dynamic WebService invocation becomes simple.

              Comment

              Working...
              X