我正在为 android 中的 DBConnection 起诉 asp.net webservice (visual studio 2008)。
它运行成功。
我的安卓代码是:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final AlertDialog ad=new AlertDialog.Builder(this).create();
TextView tv=(TextView)findViewById(R.id.tvArray);
Button btnCall=(Button)findViewById(R.id.btnCall);
btnCall.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
CallSoap cs=new CallSoap();
try
{
String name=cs.Call();
Toast.makeText(getApplicationContext(), name, Toast.LENGTH_LONG).show();
}
catch(Exception ex)
{
ad.setMessage(ex.getMessage());
}
}
});
}
和 callsoap 方法:
import java.util.ArrayList;
import org.ksoap2.SoapEnvelope;
import org.ksoap2.serialization.PropertyInfo;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.ksoap2.transport.HttpTransportSE;
import android.widget.Toast;
public class CallSoap
{
public final String SOAP_ACTION ="http://tempuri.org/GetData";
public final String OPERATION_NAME = "GetData";
public final String WSDL_TARGET_NAMESPACE = "http://tempuri.org/";
public final String SOAP_ADDRESS = "http://10.0.2.2:8080/Service1.asmx";
public CallSoap()
{
}
public String Call()
{
SoapObject req=new SoapObject(WSDL_TARGET_NAMESPACE, OPERATION_NAME);
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
SoapEnvelope.VER11);
envelope.dotNet = true;
//envelope.headerOut = security; // this is an Element[] created before
envelope.encodingStyle = SoapEnvelope.ENC;
envelope.setAddAdornments(false);
envelope.implicitTypes = false;
envelope.setOutputSoapObject(req);
HttpTransportSE httpTransport = new HttpTransportSE(SOAP_ADDRESS);
Object response=null;
try
{
httpTransport.call(SOAP_ACTION, envelope);
response = envelope.getResponse();
//Toast.makeText(this, "this is my Toast message!!! =)", Toast.LENGTH_LONG).show();
}
catch (Exception exception)
{
response=exception.toString();
}
return response.toString();
}
}
当我单击应用程序上的按钮时,它给了我错误:
android org.xmlpull.v1.xmlpullparserexception 预期 start_tag http //schemas.xmlsoap.org/soap/envelope/ 信封位置开始标签
我在堆栈上有很多关于这个的问题。
我发现它通常是由于编写了错误的服务方法而发生的。
但就我而言,我检查了所有这些。每件事都是正确的。
您还可以检查:我有我正在运行的服务的快照,其中给出了每一件事:
请帮我。