【发布时间】:2014-01-16 09:07:17
【问题描述】:
我正在尝试使用 .Net 网络服务。我收到以下异常。
例外: org.xmlpull.v1.XmlPullParserException:预期:START_TAG {http://schemas.xmlsoap.org/soap/envelope/}信封(位置:START_TAG @2:7 in java.io.InputStreamReader@40d66380)
import android.os.AsyncTask;
import android.os.Bundle;
import android.app.Activity;
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 com.example.webserviceactivity.R;
import android.util.Log;
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 {
private final String NAMESPACE = "http://tempuri.org/";
private final String URL = "http://10.0.2.2:2351/Service1.asmx";
private final String SOAP_ACTION = "http://tempuri.org/HelloWorld";
private final String METHOD_NAME = "HelloWorld";
private String TAG = "Result";
private static String c;
Button b;
TextView tv;
EditText et;
EditText et2;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
tv = (TextView) findViewById(R.id.tv_result);
//Button to trigger web service invocation
b = (Button) findViewById(R.id.button1);
//Button Click Listener
b.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
//Create instance for AsyncCallWS
AsyncCallWS task = new AsyncCallWS();
//Call execute
task.execute();
//If text control is empty
}
});
}
public void getSum() {
Log.i(TAG, "1");
//Create request
SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
//Create envelope
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
SoapEnvelope.VER11);
//envelope.dotNet = true;
//Set output SOAP object
envelope.setOutputSoapObject(request);
//Create HTTP call object
HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
Log.i(TAG, "5");
try {
//Invole web service
androidHttpTransport.call(SOAP_ACTION, envelope);
//Get the response
SoapPrimitive response = (SoapPrimitive) envelope.getResponse();
//Assign it to Sum static variable
c = response.toString();
Log.i(TAG, "6");
} catch (Exception e) {
Log.i(TAG, e.toString());
c=e.toString();
}
}
private class AsyncCallWS extends AsyncTask<String, Void, Void> {
@Override
protected Void doInBackground(String... params) {
Log.i(TAG, "doInBackground");
getSum();
return null;
}
@Override
protected void onPostExecute(Void result) {
Log.i(TAG, "onPostExecute");
tv.setText(c + " ! ");
}
@Override
protected void onPreExecute() {
Log.i(TAG, "onPreExecute");
tv.setText("Calculating...");
}
@Override
protected void onProgressUpdate(Void... values) {
Log.i(TAG, "onProgressUpdate");
}
}
}
【问题讨论】:
-
请粘贴您的完整 LogCat 跟踪,在此异常之前,您是否收到任何空指针异常?
-
No..我没有得到空指针异常
-
我认为你已经在你的系统上实现了这个 hello world 网络服务。打开你的 wsdl 并从他们的@10.0.2.2:2351/Service1.asmx 复制命名空间。它一定是别的东西。
标签: android eclipse web-services soap