public class HelloService {
public String sayHello(String username) {
return "Hello: " + username;
}
}
以上是发布的方法,发布后显示的路径是:http://localhost:8080/eclipse4WS/services/HelloService
我的方法名为sayHello()
发布结果没有显示方法名等信息,只是提示:
HelloService
Hi there, this is an AXIS service!
Perhaps there will be a form for invoking the service here...
不知道算不算成功,后来使用webservice协议来调取此端口成功。
httpget方法:
public class newhttp {
public static void main(String[] args) throws ClientProtocolException, IOException{
String url="http://localhost:8080/eclipse4WS/services/HelloService";
String param="username="+URLEncoder.encode("000000", "utf-8");
HttpClient httpclient=new DefaultHttpClient();
httpclient.getParams().setParameter(HttpProtocolParams.HTTP_CONTENT_CHARSET, "UTF-8");
HttpGet httpget=new HttpGet(url+"?"+param);
ResponseHandler<String> responseHandler = new BasicResponseHandler();
String responseBody = httpclient.execute(httpget, responseHandler);
System.out.println(responseBody);
httpclient.getConnectionManager().shutdown();
}
}
放落上找的方法,但不能成功,是不是url不对,如何修改?
不成功报什么错?打印的结果是什么?
什么信息都没有怎么给你找问题
我看代码没什么问题,帮你查找出问题:
1、先不用httpget,直接把你的地址http://localhost:8080/eclipse4WS/services/HelloService/username=xxx在浏览器中请求,看有没有结果,如果没有那么肯定不是httpget的问题,如果浏览器中有结果,那么可以肯定是httpget的问题,请检查是否是url或者少了/等其它的问题(总之检查httpclient),httpclient别写那么多,二三句就能取到源码!