如何使用EclipseIndigo在Android中导入web服务引用?
我正在开发一个android应用程序,我必须导入一些web服务引用;目前我正在使用EclipseIndigo,我没有找到任何导入web引用选项,所以有人能帮我怎么做吗?据我所知,Android中没有任何自动创建WSDL服务引用的方法 不幸的是,您需要自己定义访问WSDL服务的类和方法如何使用EclipseIndigo在Android中导入web服务引用?,android,wcf,web-services,eclipse-indigo,Android,Wcf,Web Services,Eclipse Indigo,我正在开发一个android应用程序,我必须导入一些web服务引用;目前我正在使用EclipseIndigo,我没有找到任何导入web引用选项,所以有人能帮我怎么做吗?据我所知,Android中没有任何自动创建WSDL服务引用的方法 不幸的是,您需要自己定义访问WSDL服务的类和方法 如果您的web服务正在使用SOAP,那么您可能希望作为库进行调查,以帮助您进行服务调用。导入java.io.BufferedReader; 导入java.io.InputStream; 导入java.io.Inpu
如果您的web服务正在使用SOAP,那么您可能希望作为库进行调查,以帮助您进行服务调用。导入java.io.BufferedReader; 导入java.io.InputStream; 导入java.io.InputStreamReader; 导入java.util.ArrayList 导入org.apache.http.HttpEntity; 导入org.apache.http.HttpResponse; 导入org.apache.http.NameValuePair; 导入org.apache.http.client.HttpClient; 导入org.apache.http.client.entity.UrlEncodedFormEntity; 导入org.apache.http.client.methods.HttpPost; 导入org.apache.http.impl.client.DefaultHttpClient 公共类DbRequest{
public DbRequest() {
}
public String sendDBRequest(ArrayList<NameValuePair> httpPost) {
String result = "";
String url = "http://www.YourURL.com/android/dbservice.php";//For Online Server
//String url = "http://10.0.2.2/android/dbservice.php";
//String url = "http://192.168.1.4/android/dbservice.php";//For Local Server
InputStream is = null;
try {
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost(url);
httppost.setEntity(new UrlEncodedFormEntity(httpPost));
HttpResponse response = httpclient.execute(httppost);
HttpEntity entity = response.getEntity();
is = entity.getContent();
} catch (Exception e) {
result = e.toString();
}
try {
BufferedReader reader = new BufferedReader(new InputStreamReader(
is, "iso-8859-1"), 8);
StringBuilder sb = new StringBuilder();
String line = null;
while ((line = reader.readLine()) != null) {
sb.append(line + "\n");
}
is.close();
result = sb.toString();
} catch (Exception e) {
result = e.toString();
}
return (result);
}
公共数据库请求(){
}
公共字符串sendDBRequest(ArrayList httpPost){
字符串结果=”;
字符串url=”http://www.YourURL.com/android/dbservice.php“;//用于联机服务器
//字符串url=”http://10.0.2.2/android/dbservice.php";
//字符串url=”http://192.168.1.4/android/dbservice.php“;//对于本地服务器
InputStream=null;
试一试{
HttpClient HttpClient=新的DefaultHttpClient();
HttpPost HttpPost=新的HttpPost(url);
setEntity(新的UrlEncodedFormEntity(httppost));
HttpResponse response=httpclient.execute(httppost);
HttpEntity=response.getEntity();
is=entity.getContent();
}捕获(例外e){
结果=e.toString();
}
试一试{
BufferedReader reader=新的BufferedReader(新的InputStreamReader(
is,“iso-8859-1”),8);
StringBuilder sb=新的StringBuilder();
字符串行=null;
而((line=reader.readLine())!=null){
sb.追加(第+行“\n”);
}
is.close();
结果=sb.toString();
}捕获(例外e){
结果=e.toString();
}
返回(结果);
}
}
替换数据库服务的URL地址。它将调用它并接收字符串作为结果 web服务引用??在这个问题上需要更多信息,我甚至不知道你所说的“web服务引用”是什么意思?好的,我有一个服务url(.net web服务),我需要将这些url导入到我的项目中,我需要使用这些服务url中的类和方法。不是WCF我使用的是web服务SOK,也许您正在使用支持WSDL(web服务描述语言)的较旧的.net技术之一。不管怎样,我都不相信Eclipse有任何扩展可以读取WSDL并为您创建服务引用/类。目前我使用的是axis2java jar文件,我得到了类似“导入web引用”的选项,但在这个indigo版本中它不起作用。有错吗?那么有没有其他方法可以做到这一点呢?在我的服务url中,我有这么多的类和方法,那么我如何在android应用程序中使用它们呢?如果你想发布一些可以在Web服务上读取的数据,请在你的活动中创建上述类的实例,并通过传递httpPost对列表来调用其函数。这样做:DBService DBService=newdbservice();dbservice.sendDBRequest(httpPost);