我制作了一个 VB.Net Web 服务。这将由 IIS 7.0 中的 Android Emulator 调用。返回 2 位总和的简单方法可以正常工作,但是当我尝试在数据库 MY SQL SERVER 中插入记录时,它会生成 java.net.ServerTimeoutException。但是当我当时尝试从浏览器运行它时,它会正常工作,这意味着它能够在数据库中插入记录,但从 Android 模拟器它会给出一个异常。
package com.BuddiesHub;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
import org.ksoap2.SoapEnvelope;
import org.ksoap2.serialization.PropertyInfo;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.ksoap2.transport.HttpTransportSE;
public class Register extends Activity
{
EditText mobno,password,cnfpassword,secqus,secans;
Button register;
public final String SOAP_ACTION = "http://tempuri.org/doRegister";
public final String OPERATION_NAME = "doRegister";
public final String WSDL_TARGET_NAMESPACE = "http://tempuri.org/";
public final String SOAP_ADDRESS = "http://10.0.2.2/BuddiesHub/Service.asmx";
SoapSerializationEnvelope envelope=null;
HttpTransportSE httpTransport=null;
PropertyInfo pi=null;
SoapObject request=null;
Object response=null;
//private static final String SOAP_ACTION = "http://tempuri.org/HelloWorld";
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.register);
mobno=(EditText)findViewById(R.id.txtmobno);
password=(EditText)findViewById(R.id.txtpassword);
cnfpassword=(EditText)findViewById(R.id.txtcnfpassword);
secqus=(EditText)findViewById(R.id.txtsecqus);
secans=(EditText)findViewById(R.id.txtsecans);
register=(Button)findViewById(R.id.btnregister);
register.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
request = new SoapObject(WSDL_TARGET_NAMESPACE,OPERATION_NAME);
//mobno ,name,secqus,secans
pi=new PropertyInfo();
pi.setName("mobno");
pi.setValue(mobno.getText().toString());
pi.setType(String.class);
request.addProperty(pi);
pi=new PropertyInfo();
pi.setName("name");
pi.setValue(password.getText().toString());
pi.setType(String.class);
request.addProperty(pi);
pi=new PropertyInfo();
pi.setName("secqus");
pi.setValue(secqus.getText().toString());
pi.setType(String.class);
request.addProperty(pi);
pi=new PropertyInfo();
pi.setName("secans");
pi.setValue(secans.getText().toString());
pi.setType(String.class);
request.addProperty(pi);
envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.dotNet = true;
envelope.setOutputSoapObject(request);
httpTransport = new HttpTransportSE(SOAP_ADDRESS);
//SoapObject response=null;
// response = null;
//String result = null;
try
{
httpTransport.call(SOAP_ACTION, envelope);
response = envelope.getResponse().toString();
Toast.makeText(getBaseContext(), response.toString(), Toast.LENGTH_LONG ).show();
}
catch (Exception exception)
{
response=exception.toString();
Toast.makeText(getBaseContext(), response.toString(), Toast.LENGTH_LONG ).show();
}
} });
}
}