Search code examples
web-servicesiisc#-4.0wsdlandroid-ksoap2

Ksoap2 client returned failed to connect to /192.168.15.56(port 1122) after 60000ms


I wrote a webservice in .net. I publish the service in IIS and started it. I also edited its bindings to connect to the 1122. In firewall i added inbound and outbound rules to access my port 1122. At this point i was able to open the webservice page in my android phones browser. I used ksoap2 library in my android code to access the .net service. I tested the service first on emulator and it worked fine. When i tried to test the same code on the phone it throws exception failed to connect to /192.168.15.56(port 1122) after 60000ms. This is the part of my code that controls the ip and calls my 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);

My class to process ksoap2 looks like this:

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

Yes my pc ip is 192.168.15.56 i double checked. here is my ip cmd ipconfig my ip
The port is 1122. I can open it in my phones browser it looked like this The page in my phones browser

but instead of localhost 192.168.15.56 was shown any help! I could get.


Solution

  • I solved it i added in my web.config by default these were off so before doing this i could see local host and methods of my service in the mobile browser but not able to test them. Plus while concatination this instruction SOAP_ADDRESS= SOAP_ADDRESS="http://"+params[0]+"/myWebService.asmx";was messing up even though the path was same i was not able to open it instead of this "http://"+params[0]+"/myWebService.asmx" i hardcored the path and it worked the code is fine