开发者

how to "accept" a webservice in java?

I have a web service that returns some XML and I wa开发者_如何学JAVAnt to store this XML within my java application but I am not sure how to do this.

I feel like I might be searching for the wrong term, so any pointers/tutorials would help!

thanks


you can use spring-ws it will handle everything for you

http://static.springsource.org/spring-ws/sites/2.0/

And do something like this

public class WebServiceClient {

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

// send to an explicit URI
public void customSendAndReceive() {
    StreamSource source = new StreamSource(new StringReader(MESSAGE));
    StreamResult result = new StreamResult(System.out);
      webServiceTemplate.sendSourceAndReceiveToResult("http://localhost:8080/AnotherWebService",
        source, result);
}

}

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜