0
我有連接到Web服務的代碼段。我的應用程序有一個按鈕,當按下從服務器獲取一些數據並顯示給用戶。這很簡單,但從來沒有工作。我已閱讀所有關於我的問題的問候,但他們都沒有解決它。該代碼是從codeproject sample使用:連接到Web服務以SocketTimeoutException結束
public void onClick(View v) {
SoapObject request = new SoapObject("http://tempuri.org/", "Add");
PropertyInfo pi=new PropertyInfo();
pi.setName("a");
pi.setValue(10);
pi.setType(Integer.class);
request.addProperty(pi);
pi=new PropertyInfo();
pi.setName("b");
pi.setValue(15);
pi.setType(Integer.class);
request.addProperty(pi);
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
SoapEnvelope.VER11);
envelope.dotNet = true;
envelope.setOutputSoapObject(request);
HttpTransportSE httpTransport = new HttpTransportSE("http://grasshoppernetwork.com/NewFile.asmx");
String response="";
try
{
httpTransport.call("http://tempuri.org/Add", envelope);
response = (envelope.getResponse()).toString();
}
catch (Exception exception)
{
response=exception.toString();
}
onSoapRequestFinished(response.toString());
}
我已經加入2個權限:Network_Access和互聯網。令人驚訝的是,Web服務可以從AVD的瀏覽器訪問。
的錯誤是:
java.net.MalformedURLException: no protocol: java.net.SocketTimeoutException
at java.net.URL.<init>(URL.java:589)
at java.net.URL.<init>(URL.java:486)
at java.net.URL.<init>(URL.java:435)
at org.apache.harmony.xml.parsers.DocumentBuilderImpl.parse(DocumentBuilderImpl.java:115)
at javax.xml.parsers.DocumentBuilder.parse(DocumentBuilder.java:155)
at ir.dana.sharif.testxml.MainActivity.onSoapRequestFinished(MainActivity.java:103)
at ir.dana.sharif.testxml.MainActivity.onClick(MainActivity.java:84)
at android.view.View.performClick(View.java:5610)
at android.view.View$PerformClick.run(View.java:22265)
at android.os.Handler.handleCallback(Handler.java:751)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6077)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:865)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:755)