我正在爲我的android應用程序開發使用eclipse Helios。 我做了一個.Net網絡服務,然後我製作了一個android應用程序,我在其中使用Ksoap2 jar文件調用web服務。 我看到這個鏈接幫助http://www.codeproject.com/Articles/304302/Calling-Asp-Net-Webservice-ASMX-From-an-Android-Ap求助 我下載與依賴 了Android ksoap2.jar文件然後使用構建路徑 每一件事情順利,但添加的jar文件每當我運行或調試程序的時候,給我一個錯誤 隨叫隨到肥皂方法 BaseClassLoader.Class未找到錯誤請附上源 在log cat中,它的節目找不到類org.ksoap2.serialization。 SOAP對象甚至是類存在於庫面向BaseClassLoader.Class在Ksoap2調用Android時未發現運行時錯誤調用
This is my soap class
package com.nrf;
import org.ksoap2.SoapEnvelope;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.ksoap2.transport.HttpTransportSE;
import org.ksoap2.serialization.PropertyInfo;
import org.ksoap2.serialization.SoapObject;
public class CallSoap
{
public String SOAP_ACTION;
public String OPERATION_NAME;
public final String WSDL_TARGET_NAMESPACE = "NRF_Cargo_App";
public final String SOAP_ADDRESS = "http://localhost:5265/NRF_Cargo_Service.asmx";
public CallSoap()
{
}
public String Call(String a,String b)
{
SoapObject request = new SoapObject(WSDL_TARGET_NAMESPACE,OPERATION_NAME);
PropertyInfo pi = new PropertyInfo();
pi.setName("userName");
pi.setValue(a);
pi.setType(String.class);
request.addProperty(pi);
pi=new PropertyInfo();
pi.setName("Password");
pi.setValue(b);
pi.setType(String.class);
request.addProperty(pi);
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.dotNet = true;
envelope.setOutputSoapObject(request);
HttpTransportSE httpTransport = new HttpTransportSE(SOAP_ADDRESS);
Object response=null;
try
{
httpTransport.call(SOAP_ACTION, envelope);
response = envelope.getResponse();
}
catch (Exception exception)
{
response=exception.toString();
}
return response.toString();
}
}
This is my MainActivityclass
package com.nrf;
import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
public class MainActivity extends Activity
{
Button btnlogin;
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
btnlogin = (Button) findViewById(R.id.btnsign);
btnlogin.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
CallSoap cs = new CallSoap();
cs.OPERATION_NAME = "UserLogin";
cs.SOAP_ACTION ="NRF_Cargo_App/UserLogin";
String resp=cs.Call("Numair", "1234");
}
});
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}
Please help me for making this app run
or suggest me another easy way of calling .net web-service in android.Thanks
錯誤記錄貓
http://i.stack.imgur.com/mi5hN.png
我多次嘗試這種方法。沒有成功。我可以給你我的項目樣品,你可以自己嘗試。 – user2731688