Ksoap2套接字在android中与.Net soap webservice没有连接异常

时间:2011-09-21 04:47:35

标签: android

我已经在android中完成了以下代码,用于连接.net soap web服务,但它给出了一个错误java.net.sockettimeoutexception:Socket没有连接。

我的代码

package com.hello;

import android.app.Activity;
import org.ksoap2.SoapEnvelope;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.ksoap2.transport.HttpTransportSE;

import android.os.Bundle;
import android.widget.TextView;

public class HelloWorldActivity extends Activity {
    /** Called when the activity is first created. */


    private static final String SOAP_ACTION = "http://tempuri.org/HelloWorld";
    private static final String METHOD_NAME = "HelloWorld";
    private static final String NAMESPACE = "http://tempuri.org/";
    private static final String URL = "http://x.x.x.x/HelloWebService/HelloWebService.asmx";
    public TextView mResult;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);


        setContentView(R.layout.main); 

        mResult=(TextView)findViewById(R.id.textView2);

        try {

            SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);

            SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
            envelope.dotNet=true;
            envelope.setOutputSoapObject(request);

            HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
            androidHttpTransport.call(SOAP_ACTION, envelope);

            String result=(String)envelope.getResponse();
            mResult.setText("Content:" +result);

        } 
        catch (Exception e) 
        {
            mResult.setText(e.toString());


        }      
        }
    }

请帮帮我......!

1 个答案:

答案 0 :(得分:3)

虽然这可能有点晚了,但这就是为我解决的问题:

HttpTransportSE androidHttpTransport = new HttpTransportSE(URL,60000);

注意第二个参数,即超时值。

我必须承认很难,我不知道这个值的规模,但我认为这是以毫秒计算的。