我正在嘗試使用android做網絡服務。我使用visual studio創建了Web服務。我手動測試了Web服務,它返回了我的價值。現在,我嘗試在android中配置web服務,以便它可以返回相同的值,但是當我嘗試運行代碼時發生錯誤。 轉換爲Dalvik格式失敗,錯誤1。 需要專家的建議。謝謝運行網絡服務時出錯
以下是我的代碼。
package com.test.web;
import android.app.Activity;
import android.os.Bundle;
import org.ksoap2.SoapEnvelope;
import org.ksoap2.serialization.PropertyInfo;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapPrimitive;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.ksoap2.transport.HttpTransportSE;
import android.util.Log;
import android.widget.TextView;
import android.widget.Toast;
public class WebSrviceActivity extends Activity {
private final String WSDL_TARGET_NAMESPACE = "http://smartposter.smartag.my";
private final String SOAP_ADDRESS = "http://smartposter.smartag.my/SmartPosterV1.asmx";
private final String SOAP_ACTION = "http://smartposter.smartag.my/HelloWorld";
private final String METHOD_NAME = "HelloWorld";
private static final String URL = "http://localhost:62558/SmartPosterV1.asmx";
private Object resultsRequestSOAP = null;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// setContentView(R.layout.main);
TextView tv = new TextView(this);
setContentView(tv);
SoapObject request = new SoapObject(WSDL_TARGET_NAMESPACE, METHOD_NAME);
//SoapObject
/*request.addProperty("firstname", "John");
request.addProperty("lastname", "Williams");*/
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.setOutputSoapObject(request);
HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
try
{
androidHttpTransport.call(SOAP_ACTION, envelope);
resultsRequestSOAP = envelope.getResponse();
String[] results = (String[]) resultsRequestSOAP;
tv.setText(results[0]);
Toast.makeText(getApplicationContext(), "testig"+results[0].toString(), Toast.LENGTH_LONG).show();
}
catch(Exception ex)
{
}
}
}
你是對的。一旦我刪除了罐子。它的工作正常。謝謝。 – 2012-02-17 06:49:35