android eclipse上的web服务

时间:2012-06-05 06:26:57

标签: android web-services

我是android / eclipse(java)的新手,实际上也是这个论坛。

有没有人遇到过这种情况?

从用户那里获取输入并通过使用android / eclipse中的web服务显示相应的结果。有没有可用的例子?

非常感谢。

2 个答案:

答案 0 :(得分:1)

我发布了教程链接

这里是访问android basic ksoap android tutorial

中的Web服务的基本android教程

并且要在java中创建webservice,请使用此教程How to create java based web service

使用java编写Web服务然后使用kso​​ap库您将获得响应。然后根据您的要求格式化响应。代码供参考:

private static final String NAMESPACE = "http://tempuri.org/"; 
private static final String URL ="http://localhost/Web_Service.asmx?";// replace it by your Webservice URL
private static final String METHOD_NAME = "Function_Name";
private static final String SOAP_ACTION = "Soap Action";

SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME); 
request.addProperty("parm_name",prm_value);// Parameter for Method
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11); 
envelope.dotNet = true;
envelope.setOutputSoapObject(request);
HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
try 
{
    androidHttpTransport.call(SOAP_ACTION, envelope);//call the eb service Method
} 
catch (Exception e) 
{
    e.printStackTrace();
}//Next task is to get Response and format that response
    SoapObject response;
    response= (SoapObject) envelope.bodyIn;

答案 1 :(得分:0)