views:

144

answers:

4

I'm getting a Java Socket Exception "Operation timed out" when trying to call a .NET web service method. I've followed the many examples out there on the web to get my android to call a .net web service.

I'm running the web service using VS2010 in debug mode. The web method I'm calling is very simple -> "string GetVersion()"

I've read some posts that eclipse needs to be configured to access the internet by modifying the Proxy preferences "Preferences -> General -> Network Connections" from the Window menu item. I haven't been able to figure out exactly what I need to configure in the Proxy to get things to work if that is the problem.

I've also tried to access the .net web service root page (service.asmx) from my android with no success. I can access the asmx page with no problems using IE on the local machine. I've turned off the firewall and that didn't solve anything either. This is the first time I've tried to access a web service from a remote computer when it was running using VS2010 in debug mode.

I don't know if I have a configuration issue on the eclipse side or on the VS2010 side.

I'm also running Windows 7 Home Premium.

Any ideas? Thanks, Omar

Below is a code snippet...

private static final String SOAP_ACTION = "http://192.168.1.151/MyWebService/GetVersion";
private static final String METHOD_NAME = "GetVersion";   
private static final String NAMESPACE = "http://192.168.1.151/MyWebService"; 
private static final String URL = "http://192.168.1.151/MyService.asmx";

private void Connect()
{
    SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);

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

    HttpTransportSE androidHttpTransport = new HttpTransportSE(URL); 

    System.out.println("DEBUG >> HttpTransport.call()");

    try
    {         
       androidHttpTransport.call(SOAP_ACTION, envelope);
    }
    catch(IOException iexc)
    {
     System.out.println("EXCEPTION >> " + iexc.toString());
    }
    catch(XmlPullParserException xexc)
    {
     System.out.println("EXCEPTION >> " + xexc.toString());
    }

    try
    {
       Object result = (Object)envelope.getResponse();

       tv.setText(result.toString());
    }
    catch (SoapFault sp)
    {
     System.out.println("EXCEPTION >> " + sp.toString());
    }
}
A: 

If you run your .Net webservice in VS2010's debug mode you are most likely running a web server called Cassini. Unfortunately it is not possible to access a Cassini-hosted sites remotely:

Of course you can do some port forwarding to work around this limitation.

Josef
Thanks for the info. I will give that a try with respect to get my android to see the root asmx page. I realized I didn't mention that my android app via eclipse is on the local machine as the web service running in debug mode.
Are you using a http://localhost url?
Todd Smith
That's not possible, Android (both as emulator and device) is its own host so you won't be able to connect to your PC using `localhost`.
Josef
A: 

try deploying the service to the IIS.

Mina Samy
A: 

Obtain the "ksoap2-android" jar file from : link text [http://ksoap2-android.googlecode.com/files/ksoap2-android-assembly-2.4-jar-with-dependencies.jar]

Add this as an "Add External JAR" in your eclipse project.

Then use AndroidHttpTransport object as shown in the code snippet below :

try 
        {
            SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME); 
            request.addProperty("a", "15");
            request.addProperty("b", "20");
            SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
            envelope.dotNet=true; 
            envelope.setOutputSoapObject(request);
            AndroidHttpTransport androidHttpTransport = new AndroidHttpTransport(URL);
            androidHttpTransport.call(SOAP_ACTION, envelope);
            SoapPrimitive result = (SoapPrimitive)envelope.getResponse();
            returnMessage = result.toString();
        }
        catch (SoapFault sf){
            returnMessage = "FAULT:\n";
            String faultString = "Code: " + sf.faultcode + "\nString: " +
            sf.faultstring;
            Log.d(TAG , "fault : " + faultString);
            returnMessage += faultString;
        }
        catch( Exception e )
        {
            Log.d(TAG , "exception e = "+ e.getMessage());
            returnMessage = "Call Exception:" + e.toString();
        }


    return returnMessage;

Hope this helps....

Roy Samuel
A: 

I am having same issue. Did you solve this problem?

vvmr