我正在尝试将我的应用程序连接到我在ASP中创建并且当前正在运行的 Web 服务localhost
。该应用程序正在尝试访问Coordonate
接受 3 个整数的方法。
我已经提供了代码和LogCat。我不得不提一下,我是 Web 服务的新手。
任何帮助将不胜感激!干杯!
代码:
package Dan.Denver.Nuggets.googleMaps;
import android.app.Activity;
import android.app.AlertDialog;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.SeekBar;
import android.widget.Toast;
import android.widget.SeekBar.OnSeekBarChangeListener;
import android.widget.TextView;
import org.ksoap2.SoapEnvelope;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapPrimitive;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.ksoap2.transport.HttpTransportSE;
public class SlideBar extends Activity
{
SeekBar seekBar;
TextView textView;
Button sendButton;
private static final String SOAP_ACTION = "http://tempuri.org/Coordonate";
private static final String METHOD_NAME = "Coordonate";
private static final String NAMESPACE = "http://tempuri.org/";
private static final String URL = "http://localhost:49934/Service1.asmx";
SoapObject request;
SoapSerializationEnvelope soapEnvelope;
HttpTransportSE transport;
SoapPrimitive rezultat;
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.slidebar);
textView = (TextView)findViewById(R.id.textView);
sendButton = (Button)findViewById(R.id.bSB);
seekBar = (SeekBar)findViewById(R.id.sbSB);
seekBar.setMax(100);
seekBar.setProgress(1);
seekBar.setOnSeekBarChangeListener(new OnSeekBarChangeListener()
{
public void onStopTrackingTouch(SeekBar seekBar)
{
// TODO Auto-generated method stub
}
public void onStartTrackingTouch(SeekBar seekBar)
{
// TODO Auto-generated method stub
}
public void onProgressChanged(SeekBar seekBar, int progress,
boolean fromUser)
{
textView.setText(String.valueOf(progress + "%"));
// if(progress >= 25 && progress < 50)
// textView.setTextColor(R.color.Yellow);
// else if(progress >= 50 && progress < 75)
// textView.setTextColor(R.color.Orange);
// else if(progress >= 75 && progress <= 100)
// textView.setTextColor(R.color.Red);
// else
// textView.setTextColor(R.color.Green);
}
});
sendButton.setOnClickListener(new View.OnClickListener()
{
public void onClick(View v)
{
// TODO Auto-generated method stub
//Toast.makeText(getBaseContext(), "Drumul este congestionat in proportie de "+textView.getText().toString(), Toast.LENGTH_LONG).show();
request = new SoapObject(NAMESPACE, METHOD_NAME);
request.addProperty("latitudine", Main.latitudine);
request.addProperty("longitudine", Main.longitudine);
request.addProperty("procentTrafic", seekBar.getProgress());
soapEnvelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
soapEnvelope.dotNet = true;
soapEnvelope.setOutputSoapObject(request);
transport = new HttpTransportSE(URL);
try
{
transport.call(SOAP_ACTION, soapEnvelope);
rezultat = (SoapPrimitive)soapEnvelope.getResponse();
Toast.makeText(getBaseContext(), rezultat.toString(), Toast.LENGTH_LONG).show();
}
catch(Exception e)
{
e.printStackTrace();
}
}
});
}
}
日志猫:
07-01 17:11:56.790: E/AndroidRuntime(1029): FATAL EXCEPTION: main
07-01 17:11:56.790: E/AndroidRuntime(1029): java.lang.NoClassDefFoundError: org.ksoap2.serialization.SoapObject
07-01 17:11:56.790: E/AndroidRuntime(1029): at Dan.Denver.Nuggets.googleMaps.SlideBar$2.onClick(SlideBar.java:80)
07-01 17:11:56.790: E/AndroidRuntime(1029): at android.view.View.performClick(View.java:2408)
07-01 17:11:56.790: E/AndroidRuntime(1029): at android.view.View$PerformClick.run(View.java:8816)
07-01 17:11:56.790: E/AndroidRuntime(1029): at android.os.Handler.handleCallback(Handler.java:587)
07-01 17:11:56.790: E/AndroidRuntime(1029): at android.os.Handler.dispatchMessage(Handler.java:92)
07-01 17:11:56.790: E/AndroidRuntime(1029): at android.os.Looper.loop(Looper.java:123)
07-01 17:11:56.790: E/AndroidRuntime(1029): at android.app.ActivityThread.main(ActivityThread.java:4627)
07-01 17:11:56.790: E/AndroidRuntime(1029): at java.lang.reflect.Method.invokeNative(Native Method)
07-01 17:11:56.790: E/AndroidRuntime(1029): at java.lang.reflect.Method.invoke(Method.java:521)
07-01 17:11:56.790: E/AndroidRuntime(1029): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
07-01 17:11:56.790: E/AndroidRuntime(1029): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
07-01 17:11:56.790: E/AndroidRuntime(1029): at dalvik.system.NativeStart.main(Native Method)
07-01 17:12:00.229: I/Process(1029): Sending signal. PID: 1029 SIG: 9