【问题标题】:Ksoap2 client returned failed to connect to /192.168.15.56(port 1122) after 60000msKsoap2 客户端在 60000 毫秒后返回无法连接到 /192.168.15.56(端口 1122)
【发布时间】:2018-04-04 00:11:55
【问题描述】:

我在 .net 中编写了一个网络服务。我在 IIS 中发布服务并启动它。我还编辑了它的绑定以连接到 1122。在防火墙中,我添加了入站和出站规则来访问我的端口 1122。此时我能够在我的 android 手机浏览器中打开 web 服务页面。我在我的 android 代码中使用 ksoap2 库来访问 .net 服务。我首先在模拟器上测试了该服务,它运行良好。当我试图在手机上测试相同的代码时,它会抛出异常 60000 毫秒后无法连接到 /192.168.15.56(端口 1122)。 这是我的代码中控制 ip 并调用我的 asynctask 的部分

   String inputId=editText1.getText().toString();
   //String params[]=new String[]{"10.0.2.2:1122",inputId};
   String params[]=new String[]{"192.169.15.56:1122",inputId};
    new MyAsyncTask().execute(params);

我处理 ksoap2 的类如下所示:

class MyAsyncTask extends AsyncTask<String, Void, String>
    {
        public String SOAP_ACTION= "http://threepin.org/findUserNameById";
        public String OPERATION_NAME="findUserNameById";
        public String WSDL_TARGET_NAMESPACE="http://threepin.org/";
        public String SOAP_ADDRESS;
        private SoapObject request;
        private HttpTransportSE httpTransport;
        private SoapSerializationEnvelope envelope;
        Object response=null;

        @Override
        protected void onPreExecute() {
            super.onPreExecute();
            progressBar.setVisibility(View.VISIBLE);

        }

        @Override
        protected String doInBackground(String... params) {
            SOAP_ADDRESS="http://"+params[0]+"/myWebService.asmx";
            request=new SoapObject(WSDL_TARGET_NAMESPACE,OPERATION_NAME);
            PropertyInfo pi=new PropertyInfo();
            pi.setName("Id");
            pi.setValue(Integer.parseInt(params[1]));
            pi.setType(Integer.class);
            request.addProperty(pi);
            pi=new PropertyInfo();
            envelope=new SoapSerializationEnvelope(SoapEnvelope.VER11);
            envelope.dotNet=true;
            envelope.setOutputSoapObject(request);
            httpTransport=new HttpTransportSE(SOAP_ADDRESS,60000);
            try
            {
                httpTransport.call(SOAP_ACTION,envelope);
                response=envelope.getResponse();
            }
            catch (Exception e)
            {
                response=e.getMessage();
            }

            return response.toString();
        }
        @Override
        protected void onPostExecute(final String result) {
            super.onPostExecute(result);
            mhandler.post(new Runnable() {
                @Override
                public void run() {
                    textView1.setText(result);
                    progressBar.setVisibility(View.GONE);
                }
            });
        }

是的,我的电脑 IP 是 192.168.15.56,我仔细检查了一遍。这是我的 ip
端口是 1122。我可以在手机浏览器中打开它,看起来像这样

但没有显示 localhost 192.168.15.56 任何帮助!我可以得到。

【问题讨论】:

    标签: web-services iis c#-4.0 wsdl android-ksoap2


    【解决方案1】:

    我解决了我在 web.config 中添加的默认情况下这些是关闭的,所以在这样做之前我可以在移动浏览器中看到我的服务的本地主机和方法,但无法测试它们。另外,虽然连接这条指令 SOAP_ADDRESS= SOAP_ADDRESS="http://"+params[0]+"/myWebService.asmx"; 即使路径相同我也无法打开它而不是这个“http: //"+params[0]+"/myWebService.asmx" 我对路径进行了硬核化,代码很好

    【讨论】:

      猜你喜欢
      • 2017-07-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-11-02
      • 1970-01-01
      • 2012-09-17
      • 2013-04-27
      • 2016-11-06
      相关资源
      最近更新 更多