如何在java中“接受”web服务?

时间:2011-06-21 22:54:55

标签: java xml web-services

我有一个返回一些XML的Web服务,我想将这个XML存储在我的java应用程序中,但我不知道该怎么做。

我觉得我可能正在寻找错误的术语,所以任何指针/教程都会有所帮助!

感谢

1 个答案:

答案 0 :(得分:0)

你可以使用spring-ws它会为你处理一切

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

做这样的事情

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

}