2012-09-09 22 views
0

我製作了一個VB.Net Web服務。這將從IIS 7.0的Android模擬器中調用。返回2位數的總和的簡單方法工作正常,但是當我嘗試在數據庫MY SQL SERVER中插入記錄時,它將生成java.net.ServerTimeoutException。但是,當我嘗試從瀏覽器運行它當時它會正常工作意味着它能夠在數據庫中插入記錄,但從Android模擬器它會給一個例外。VB.Net Web服務中的java.net.ServerTimeoutException

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

}

回答

0

你加

<uses-permission android:name="android.permission.INTERNET"/> 

到AndroidManifest.xml?

+0

尊敬的傑夫,是的,我在AndroidManifest.xml文件中添加了該權限。 不處理數據庫的簡單方法是調用成功並返回真值,但只有處理數據庫的方法纔會生成異常。 –