繁体   English   中英

调用没有wsdl的Web服务

[英]Calling a web service with no wsdl

我想编写一个Java程序来调用Web服务。 WSDL不适用于此Web服务。 我已经编写了程序来调用具有wsdl的Web服务。 在这里,我不知道如何进行。 也无法在Internet中找到许多样本。

我可以使用更好的框架吗? 我正在从Web服务获取JSON输出。

我正在寻找编写可能的最佳案例的选项(如果我可以编写一个通用程序,而无需做太多更改就可以将其用于许多Web服务,那就太好了)

好吧,有几种消耗休息服务的方法。

使用Spring框架:

import org.springframework.web.client.RestTemplate

RestTemplate restTemplate = new RestTemplate();
User user = restTemplate.getForObject("http://localhost:8080/users/2", User.class);
System.out.println("Username:    " + user.getUsername());

使用apache httpclient:

DefaultHttpClient httpClient = new DefaultHttpClient();
HttpGet getRequest = new HttpGet("http://localhost:8080/users/2");
HttpResponse response = httpClient.execute(getRequest);
HttpEntity httpEntity = response.getEntity();
String userString = EntityUtils.toString(httpEntity);
// Transform 'userString' into object using for example GSON:
Gson gson = new Gson();
User user = gson.fromJson(userString, User.class);
System.out.println("Username:    " + user.getUsername());

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM