我是android的新手,试图通过ksoap2调用android中的web服务但是还没有成功。当我运行这个项目时,它正在抛出“Host is Unresolved:paras:80”异常。请帮帮我摆脱这个问题。
这是我的java代码: -
import org.ksoap2.SoapEnvelope;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.ksoap2.transport.HttpTransportSE;
import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.widget.TextView;
public class HelloWebService extends Activity{
String SOAP_ACTION="http://tempuri.org/HelloWorld";
String METHOD_NAME = "HelloWorld";
String NAMESPACE = "http://tempuri.org/";
String URL = "http://paras/Webservice/test.asmx";
TextView tv1,tv2,tv3;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.hello);
tv1 = (TextView)findViewById(R.id.tv1);
tv2 = (TextView)findViewById(R.id.tv2);
// tv3 = (TextView)findViewById(R.id.tv3);
Hello();
}
public void Hello(){
// SoapObject results = null;
SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
Log.d("request", request.toString());
// request.addProperty("Celsius", str);
// Log.d("request", request.toString());
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
Log.d("envelope", envelope.toString());
envelope.dotNet = true;
envelope.setOutputSoapObject(request);
Log.d("envelope", envelope.toString());
HttpTransportSE aht = new HttpTransportSE(URL);
Log.d("aht", aht.toString());
try
{
aht.call(SOAP_ACTION, envelope);
SoapObject results = (SoapObject)envelope.getResponse();
Log.d("result", results.toString());
tv1.setText(results.toString());
}
catch (Exception e)
{
tv2.setText(e.getMessage());
}
}
}
答案 0 :(得分:0)
您的网址缺少顶级域名(.com,.edu,.net等)。