Click here to Skip to main content
15,885,650 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Dear Professionals,

Im using ksoap2 classes for invoking asp.net Web service methods in an android application guided by examples from this site. I am getting a java.net socket timed out exception.

Kindly help me figure out mistake in the code.

What I have tried :

I have added <uses-permission android:name="android.permission.INTERNET" xmlns:android="#unknown"> in the manifest and also added the library ref in the Build path etc.,

I have ensured the ASP.net webservice works well from other .net apps and from the explorer.

I have googled for several solutions online. But didn't find one to solve my issue or may be not to my understanding.


Please Note : I have worked on SOAP with android using ksoap2 in earlier projects and was through. This time I'm missing something. Please help.

Thanks in advance.

package com.Test.testtvgrm;

import java.io.IOException;

import org.apache.http.client.HttpResponseException;
import org.ksoap2.SoapEnvelope;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.ksoap2.transport.HttpTransportSE;
import org.xmlpull.v1.XmlPullParserException;

public class TestWS 
{
    public String SoapAction = "http://192.168.5.28/GetFolio";
    public String WSDLTargetNameSpace = "http://192.168.5.28/";
    public String SoapAddress = "http://192.168.5.28/grmserver/service.asmx";
	
    public TestWS()
    {

    }  
    
    public String CallFunc(int mfunc,String mpara)
    {
    	Object response = null;		
	SoapObject sorequest = new SoapObject(WSDLTargetNameSpace, "GetFolio");	  
    	String[] mparavalues = mpara.split("%");
	if (mfunc == 1)
	{
	    sorequest.addProperty("mpath", mparavalues[1]);
	    sorequest.addProperty("mroomno",mparavalues[2]);
	}    	
	SoapSerializationEnvelope soenvelope = new SoapSerializationEnvelope
        (SoapEnvelope.VER11);
	soenvelope.dotNet = true;
	soenvelope.setOutputSoapObject(sorequest);    	
	HttpTransportSE httpTransport = new HttpTransportSE(SoapAddress);
	httpTransport.debug=true;
	try
	{
	    httpTransport.call(SoapAction, soenvelope);
	    response = soenvelope.getResponse();
	}
	catch (HttpResponseException e) 
	{             
            e.printStackTrace();
	} 
	catch (IOException e) 
	{               
            e.printStackTrace();
	} 
        catch (XmlPullParserException e) 
        {                
            e.printStackTrace();
	}       
    	return response.toString();
    }
}


I'm calling the 'CallFunc' method from another class which invokes a background method to do the task. That code is as below :

Task_GetFolio = new GetFolio();
Task_GetFolio.execute((Void) null);


The background task is in this class :

public class GetFolio extends AsyncTask<Void, Void, Boolean>
{
@Override
protected Boolean doInBackground(Void... params)
{
    try
    {
    TestWS mobj = new TestWS();
    String mret = mobj.CallFunc(1, "%c:\\%1%");
    FolioFetched=true;
    }
    catch (Exception e1)
    {
    FolioFetched=false;
    }
    return FolioFetched;
}

    @Override
protected void onPostExecute(final Boolean success)
{
    Task_GetFolio=null;
    finish();
}

@Override
protected void onCancelled()
    {
    Task_GetFolio=null;
    finish();
}
}
Posted
Updated 12-Nov-15 0:29am
v2

1 solution

Local Firewall was the issue. I allowed World Wide Web Services (HTTP) in the firewall advanced settings which solved the problem for me.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900