2012-07-01 100 views
0

我想我的應用程序連接到我的ASP創建,目前在localhost運行的Web服務的Android應用程序連接到ASP .NET Web服務。該應用程序試圖訪問採用3個整數的Coordonate方法。錯誤使用kso​​ap2

我所提供的代碼和logcat的。我不得不提到,我是網絡服務的新手。

任何幫助將不勝感激!乾杯!

代碼:

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(); 
      }   
     } 
    }); 
} 
} 

logcat的:

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 

回答

2

嘗試在以下符合你係統的IP地址替換本地主機。

private static final String URL = "http://localhost:49934/Service1.asmx"; 

這可能對你有幫助。

至於即使你是在模擬器同一系統上運行然後測試也都asp.net和Android有本地主機不同的IP在某些情況下也許10.0.2.2。

相關問題