我想從Android應用調用asmx Web服務。今天從字面上開始了一些Android開發。我一直在關注我在網上和在這裏找到的各種解決方案,看起來比預期更困難。我嘗試了各種解決方案,並且使用KSoap2似乎是最簡單的方法來實現這一點,以及如果我能得到它的工作。從Android應用調用Web服務似乎掛起
我有下面的代碼工作,直到一個觀點:
private class CallWebService extends AsyncTask<Void, Void, Void> {
private static final String SOAP_ACTION = "http://tempuri.org/GetUser";
private static final String METHOD_NAME = "GetUser";
private static final String NAMESPACE = "http://tempuri.org/";
private static final String URL = "http://160.10.1.79:59315/Service1.asmx";
TextView tv;
@Override
protected Void doInBackground(Void... params) {
tv=(TextView)findViewById(R.id.txtMessage);
try {
SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.dotNet=true;
envelope.setOutputSoapObject(request);
HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
androidHttpTransport.call(SOAP_ACTION, envelope);
Object result = (Object)envelope.getResponse();
tv.setText(result.toString());
}
catch (Exception e) {
tv.setText(e.getMessage());
}
return null;
}
}
似乎在該行androidHttpTransport.call(SOAP_ACTION, envelope);
任何想法,爲什麼掛?這是正確的方法嗎?我應該朝另一個方向看嗎?
你是什麼意思它掛起?它掛在那裏幾秒鐘或無限期地? –
無限期掛起。不會拋出超時異常或任何異常。我只需要停止它手動運行。我將嘗試更新版本的KSoap2,看看它是否有所作爲。我認爲我使用的版本是從2006年開始的! – anothershrubery