Share via


System.Net.WebException: Error: ConnectFailure (Network is unreachable)

Question

Monday, October 9, 2017 3:02 PM

Hi, My webservice is working if I run app manualy but application must run automatically after device boot up. Unfortunately my app throw this exception:

Time Device Name Type PID Tag Message 10-09 05:04:52.256 Genymotion Samsung Galaxy S7 - 6.0.0 - API 23 - 1440x2560 Error 1453 AndroidRuntime android.runtime.JavaProxyThrowable: System.Net.WebException: Error: ConnectFailure (Network is unreachable) > System.Net.Sockets.SocketException: Network is unreachable at System.Net.Sockets.Socket.Connect (System.Net.EndPoint remoteEP) [0x000b6] in <6c708cf596db438ebfc6b7e012659eee>:0 at System.Net.WebConnection.Connect (System.Net.HttpWebRequest request) [0x0016d] in <6c708cf596db438ebfc6b7e012659eee>:0 End of inner exception stack trace at System.Web.Services.Protocols.SoapHttpClientProtocol.Invoke (System.String method_name, System.Object[] parameters) [0x000a7] in <3f9824dbe67544e1805773e0a3dbdf6b>:0 at GWAWE.localhost.Service1.Get_Data () [0x00001] in <1baad81b40d64c6886bf076df034661f>:0 at (wrapper remoting-invoke-with-check) GWAWE.localhost.Service1:Get_Data () at gwawe.MainActivity.BuildLayout () [0x00031] in <1baad81b40d64c6886bf076df034661f>:0 at gwawe.MainActivity.OnCreate (Android.OS.Bundle savedInstanceState) [0x0004e] in <1baad81b40d64c6886bf076df034661f>:0 at Android.App.Activity.n_OnCreate_Landroid_os_Bundle_ (System.IntPtr jnienv, System.IntPtr native__this, System.IntPtr native_savedInstanceState) [0x0000f] in <9663139ab15947a89e15a6bcd9621f68>:0 at (wrapper dynamic-method) System.Object:e6ea694d-cf84-4098-a161-481a5ad1d4ae (intptr,intptr,intptr) at md5a9dcb246785c0066d52ff25b77e1a72d.MainActivity.n_onCreate(Native Method) at md5a9dcb246785c0066d52ff25b77e1a72d.MainActivity.onCreate(MainActivity.java:29) at android.app.Activity.performCreate(Activity.java:6237) at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1107) at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2369) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476) at android.app.ActivityThread.-wrap11(ActivityThread.java) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:148) at android.app.ActivityThread.main(ActivityThread.java:5417) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616) Force finishing activity GWAWE.gwawe/md5a9dcb246785c0066d52ff25b77e1a72d.MainActivity

Does anybody have a clue what is going on here?

All replies (3)

Tuesday, October 10, 2017 6:08 AM

Hello @serasm ,

first => have you add the permission to connect to internet in the manifest file ? second => if you can call your web service in manual mode and it's ok => now if you find to call automatically call your webservice after device reboot add PERHPAS a timer before to call the web service ... i think perhpas something isn't load ...

i'm not an expert :)


Tuesday, October 10, 2017 6:32 AM

Yes, I add internet permission in manifest before I created this topic. Below is my android manifest file content.

<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="html-link" package="GWAWE.GWAWE" android:versionCode="1" android:versionName="1.0" android:installLocation="auto"> <uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" /> <uses-sdk android:minSdkVersion="23" android:targetSdkVersion="23" /> <application android:label="Aplikacja Magazynowa"> </application> </manifest>

And my receiver class:

[BroadcastReceiver]
    [IntentFilter(new[] { Intent.ActionBootCompleted }, Priority = (int)IntentFilterPriority.LowPriority)]
    class StartReceiver : BroadcastReceiver
    {
        public override void OnReceive(Context context, Intent intent)
        {

            Thread.Sleep(5000);
            Ping myPing = new Ping();

            PingReply pingReply = myPing.Send("192.168.5.218", 1000);

    if (pingReply != null)
            {
                 if ((intent.Action != null) &&
                 (intent.Action == Android.Content.Intent.ActionBootCompleted))
                 {
                     Intent serviceStart = new Intent(context, typeof(MainActivity));
                     serviceStart.AddFlags(ActivityFlags.NewTask);
                     context.StartActivity(serviceStart);
                 }
             }
        }
    }

In receiver I tried to delay application start.

My Visual Studio with Xamarin and Genymotion android emulator is up to date.


Tuesday, October 10, 2017 6:51 AM

Problem was an android, I have to add Thread.Sleep() to delay app start because Wi-Fi must have a few seconds to get to work.