System.Net.WebException: Error: NameResolutionFailure when Calling WCF Services in Mono Android Appl

SreeniSreeni INMember

I am working on Mono Android Mobile applicaiton. I am calling my WCF Services
in my applicaiton, I added wcf services using ->Add WebRefernce option of
Project Menu. My Problem is I am getting exception when i am running the
calling the wcf services on the device.

Exception:

{System.Net.WebException: Error: NameResolutionFailure at
System.Net.HttpWebRequest.EndGetRequestStream (IAsyncResult asyncResult)
[0x00000] in :0

at System.Net.HttpWebRequest.GetRequestStream () [0x00000] in :0 at
System.Web.Services.Protocols.SoapHttpClientProtocol.Invoke (System.String
method_name, System.Object[] parameters) [0x00000] in :0 }

My device has internet connection using WiFi connection to get and post data

and another way

I tried calling the services using Mobile
Data(Cellular Data) i.e with the Mobile NetWork Provider's internet
connection.. This time i am getting a different exception..

{System.Net.WebException: The request failed with HTTP status 404: NotFound at
System.Web.Services.Protocols.SoapHttpClientProtocol.ReceiveResponse
(System.Net.WebResponse response,
System.Web.Services.Protocols.SoapClientMessage message,
System.Web.Services.Protocols.SoapExtension[] extensions) [0x00000] in :0 at
System.Web.Services.Protocols.SoapHttpClientProtocol.Invoke (System.String
method_name, System.Object[] parameters) [0x00000] in :0 at
AndroidWCFExample.WirelessService.SAGServer.ProcessSomeUpdate
(AndroidWCFExample.WirelessService.WebServicesClient oClientInfo, System.String
ParameterInfo) [0x00001] in C:\Some Dotnet
Examples\AndroidWCFExample\AndroidWCFExample\Web
References\WirelessService\Reference.cs:1232 at (wrapper
remoting-invoke-with-check)
AndroidWCFExample.WirelessService.SAGServer:ProcessSomeUpdate
(AndroidWCFExample.WirelessService.WebServicesClient,string) at
AndroidWCFExample.EmployeeInfoActivity.button_Click (System.Object sender,
System.EventArgs e) [0x0007a] in C:\Some Dotnet
Examples\AndroidWCFExample\AndroidWCFExample\EmployeeInfoActivity.cs:79 }

Note:

This is working Correctly. when i run application on android emulator. I am getting correct result.

It's Debug build. I have net work permission also. I have "" in ManiFest.xml file. Even i
tried changing the build from "Debug" to "Release" mode and executed the
application. It's giving the same Error on the device , but it's giving result
in emulator. No Exception is thrown on emulator.

I am searching for solution to fix this, but not getting correct answer. So
Please let me know what i need to do, to get it fixed. Please help me out.

Answers

  • YuriShteinmanYuriShteinman CAUniversity ✭✭

    I have the same problem. Not always but often

  • YuriShteinmanYuriShteinman CAUniversity ✭✭

    In my case the problem was unstable/bad WiFi connection in the office. When I
    connected to good WiFi the problem was gone. I will keep an eye on it to see if
    it comes back.

  • ForceMagicForceMagic USMember ✭✭

    I ran into the same issue and we seems to find out the source of the problem in that post : http://forums.xamarin.com/discussion/7327/system-net-webexception-error-nameresolutionfailure#latest

    basically, rmacias linked to this google problem : https://code.google.com/p/android/issues/detail?id=58230

    which is related to the Nexus devices along with the Wifi.

  • KeyzerSKeyzerS NOMember ✭✭

    I had this too. Basically, it seems permission for Internet is not required in debug, at least for this app, but i need it checked when its going for release. One click in AndroidManifest.

  • v3yr0nv3yr0n USUniversity ✭✭
    edited February 2016

    Just add <uses-permission android:name="android.permission.INTERNET" /> to the android manifest

  • xjb3b4xjb3b4 USMember

    @v3yr0n said:
    Just add <uses-permission android:name="android.permission.INTERNET" /> to the android manifest

    I tried this solution but it didn't work

  • AndiBunasAndiBunas USMember

    That worked for me. Thanks for the pointer. Didn't realize release builds were the only ones enforcing permissions

  • RavindraKumarRavindraKumar USMember ✭✭

    Thanks @v3yr0n !
    It really works for me.

  • SreeniSreeni INMember

    I did using of WCF Services on my android application in a different way.
    1) I am generating Proxy with web services url using command line like below
    C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\Bin>svcutil /target:code /out:D:/SreeSree/ServiceReference
    http://192.168.9.156/WebServicesGDEV/Service1.svc?wsdl /config:D:/SreeSree/ServiceConfig

    Executing above command line will give you files
    1) ServiceRefrence.cs - you will get actual service,operation,data contracts in this file.
    2) ServiceConfig.config - you will get bindings and endpoint tags in this file.

    In my application i am using only servicerefrence.cs file , Right Click Project -> Add existing file -> Navigate and browse servicerefrence.cs file and add it to project in mobile application.
    Endpoints : I am directly giving end points by calling some generic methods with customization as per my requirement.

    Below code will give and idea

    // I am using BasicHttpBinding so i am always configuring binding with below routine before calling service.

       public class Mobile_Search : ALHandlerBase
    

    {
    Gold.GWebServices.gData oResult;
    EndpointAddress ep;
    public static BasicHttpBinding oBinding;

       public static void ConfigureClientInfo()
        {
        XElement bootDataNode = null;
    
            oBinding = new BasicHttpBinding()
            {
                Name = "basicHttpBinding",
                MaxReceivedMessageSize = 67108864
            };
    
            oBinding.ReaderQuotas = new System.Xml.XmlDictionaryReaderQuotas()
            {
                MaxArrayLength = 2147483646,
                MaxStringContentLength = 5242880
            };
    
            // var timeout = new TimeSpan(0, 5, 0);
            oBinding.SendTimeout = new TimeSpan(0, 1, 0);
            oBinding.OpenTimeout = new TimeSpan(0, 1, 0);
            oBinding.ReceiveTimeout = new TimeSpan(0, 20, 0);
        }
    
        void button_loginClick(object sender, EventArgs e)
        {
            ConfigureClientInfo();
            ep = new EndpointAddress("http://192.168.9.156/WebServicesGDEV/Service1.svc/Service1");
            GoldClient oGoldClient = new GoldClient(oBinding, ep);
            oResult = oGoldClient.LoginMobileUser(Global.gstrUsername, Database.GetSavedPassword(), "en-us");
            if (oResult.Result == "1")
        {
             if (oResult.Data != null && oResult.Data != "")
                          {
                  Utility.ShowMessageBox("Login Successful.");
                }
            }   
        }       
    

    }
    Only minor problem is , You need to generate new proxy class by command line whenever there is addition of new service contracts/operation contracts (or) any changes to existing services. Other than that this is working well for me and i hope it will also help you.

    Thanks
    Sreeni

Sign In or Register to comment.