初学Android,很多不懂,各位勿取笑!
低级问题,可能看了都笑,但希望各位不吝教点:
错误提示如下
“java.net.ConnectException: failed to connect to localhost/127.0.0.1 (port 54311) after 20000ms: isConnected failed: ECONNREFUSED (Connection refused)”
服务代码,很简单:[WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [ToolboxItem(false)]
    // 若要允许使用 ASP.NET AJAX 从脚本中调用此 Web 服务,请取消对下行的注释。
    // [System.Web.Script.Services.ScriptService]
    public class Service1 : System.Web.Services.WebService
    {        [WebMethod]
        public string HelloWorld()
        {
            return "Hello World";
        }
        [WebMethod(Description = "返回字符串")]
        public string GetString()
        {
            return "return string";
        }
        [WebMethod(Description = "两值求合")]
        public double GetSum(double a, double b)
        {
            return a + b;
        }
    }
Android代码String url="http://localhost:54311/Service1.asmx";  
String nameSpace = "http://localhost:54311/";     
String methodName = "GetString";    
请求WebServiceprotected Object CallWebService(){   
                String SOAP_ACTION = nameSpace + methodName;    
                //创建SoapObject实例   
                SoapObject request=new SoapObject(nameSpace,methodName);   
                //生成调用web service方法的soap请求消息   
                SoapSerializationEnvelope envelope=new SoapSerializationEnvelope(SoapEnvelope.VER11);   
                //设置.net web service   
                envelope.dotNet=true;   
                envelope.bodyOut=request;
                (new MarshalBase64()).register(envelope);
                //发送请求   
                //envelope.setOutputSoapObject(request);   
                //请求参数   
                if(params != null && !params.isEmpty() ){   
                        for(Iterator it=params.entrySet().iterator();it.hasNext();){   
                                Map.Entry e=(Entry) it.next();   
                                request.addProperty(e.getKey().toString(),e.getValue());   
                        }   
                }   
                //   
                HttpTransportSE htse = new HttpTransportSE(url);
                SoapObject result=null;   
                try{   
                        //web service请求   
                        //androidHttpTrandsport.call(SOAP_ACTION, envelope);
                 htse.call(SOAP_ACTION, envelope);
                        //得到返回结果   
                        result=(SoapObject) envelope.getResponse();   
                }catch(Exception ex){   
                        ex.printStackTrace();   
                }   
                return result;   
                   
        } 
在上面代码htse.call(SOAP_ACTION, envelope);像上文那样的错误望大神多指点androidwebservice

解决方案 »

  1.   

    "http://localhost:54311/"
    把localhost改成你服务器的ip再试试
      

  2.   

    String url="http://ip:54311/Service1.asmx?wsdl"; 
      

  3.   

    这个主要就是ip的问题,之前我也遇到过,只有最后改成服务器的ip地址才能连通
      

  4.   

    问一下,如果webserviceIP改了,怎样在android端修改url,就像修改webconfig文件中的连接字符串那样修改。
      

  5.   

    看一下你的引入的Ksoap2 ja包 是否在
    order and Export里打钩了
      

  6.   

    看一下你的引入的Ksoap2 ja包 是否在
    order and Export里打钩了
      

  7.   

    还有 地址写localhost我试过是不对的
    那个 .net  地址加不加?wsdl无所谓 
      

  8.   

    你的服务端代码生成了发布在IIS了吗?