如何解决java.net.sockettimeoutexception [英] how to solve java.net.sockettimeoutexception

查看:66
本文介绍了如何解决java.net.sockettimeoutexception的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图使用eclipse和android仿真器使用android应用程序调用c#Web服务,该Web服务也是我自己开发的,并且该Web服务工作正常.但是当我尝试通过andriod应用程序访问它时,它给出了java.net.SocketTimeOutException作为异常.我也给了互联网许可.这是我的代码


am trying call a c# web service using android application,using the eclipse and android emulater, the web service is also developed my me and the web service is works fine. but when i try access it through the andriod application it gives and exception as java.net.SocketTimeOutException. i gave the internet permission also. here is my code


public class Web01Activity extends Activity {
	
	
private static final String SOAP_ACTION = "http://tempuri.org/getadd";
	//private static final String SOAP_ACTION1 = "http://tempuri.org/getmul";

    private static final String METHOD_NAME = "getadd";

    private static final String NAMESPACE = "http://tempuri.org/";
    private static final String URL = "http://localhost:51173/WebSite6/Service.asmx";

	
	
	
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        final EditText tv=(EditText)findViewById(R.id.editText1);
        final EditText tv2=(EditText)findViewById(R.id.editText2);
        final EditText tv3=(EditText)findViewById(R.id.editText3);
        
   final    Button bt1=(Button)findViewById(R.id.button1);
   final    Button bt2=(Button)findViewById(R.id.button2);
       
    

   
     
      // bt11(num1,num2);
     

     
     bt1.setOnClickListener(new OnClickListener() {
		
		public void onClick(View v) {
			// TODO Auto-generated method stub
			try
			{
				String name=tv.getText().toString();
				String nam=tv2.getText().toString();
				int num1=Integer.parseInt(name);
				int num2=Integer.parseInt(nam);
				
	            SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
	            request.addProperty("a",num1 );
	            request.addProperty("b",num2);
	            SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
	            envelope.dotNet=true;
	            envelope.setOutputSoapObject(request);
	            HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
	            androidHttpTransport.call(SOAP_ACTION, envelope);
	            Object result = (Object)envelope.getResponse();
	           tv3.setText(result.toString());
				
			}
			catch (Exception e) {
				tv3.setText(e.toString());
			}
						
		}
	});
       

--------------------------manifestfile------------------------------


<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.padd.Web01"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk android:minSdkVersion="10" />

    <application
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name" >
        <activity
            android:name=".Web01Activity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
              

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>
<uses-permission android:name="android.permission.INTERNET"> </uses-permission>

</manifest>



plz help

推荐答案

In Strung URL "localhost" means android device's localhost not the computer's

replace below

private static final String URL = "http://localhost:51173/WebSite6/Service.asmx";

with

private static final String URL = "http://10.0.2.2:51173/WebSite6/Service.asmx";


这篇关于如何解决java.net.sockettimeoutexception的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆