manrysj manrysj - 4 years ago 268
Android Question

Xamarin WCF Fails in Release Mode

Platform: Xamarin Studio 4

Target Mobile: Android

I have an android app that calls a WCF service using basicHttpBinding that I have been working on using Xamarin Studio 4 that is running perfectly fine while in Debug Mode. To simplify things while troubleshooting this, I am calling a "Hello World" function of the WCF. No input parameters and only a string output.

In debug mode, I get the "Hello World" response. When I switch the application build to "Release", and run the application again, I get the following error message:

System.ServiceModel.EndpointNoFoundException: A system exception has occured. ---> System.Net.WebException: Error: ConnectFailure (No route to host) ---> System.Net.Sockets.SocketExcpetion: No route to host at System.Net.Sockets.Socket.Connect (System.Net.EndPoint remoteEP) [0x00000] in filename unknown: 0

The code that is calling the WCF is:

BasicHttpBinding binding = CreateBasicHttp ();
BTSMobileWcfClient _client = new BTSMobileWcfClient (binding, endPoint);
_client.SayHelloCompleted += ClientOnSayHelloCompleted;

private static BasicHttpBinding CreateBasicHttp()
BasicHttpBinding binding = new BasicHttpBinding
Name = "basicHttpBinding",
MaxBufferSize = 2147483647,
MaxReceivedMessageSize = 2147483647
TimeSpan timeout = new TimeSpan(0, 0, 30);
binding.SendTimeout = timeout;
binding.OpenTimeout = timeout;
binding.ReceiveTimeout = timeout;
return binding;

private void ClientOnSayHelloCompleted(object sender, SayHelloCompletedEventArgs sayHelloCompletedEventArgs)
string msg = null;

if (sayHelloCompletedEventArgs.Error != null)
msg = sayHelloCompletedEventArgs.Error.ToString();
else if (sayHelloCompletedEventArgs.Cancelled)
msg = "Request was cancelled.";
msg = sayHelloCompletedEventArgs.Result.ToString();
RunOnUiThread(() =>{
var lblSignInError = FindViewById<TextView> (Resource.Id.lblSignInError);
lblSignInError.Text = msg;

The BTSMobileWcfClient is a .cs file created by using the tool SLsvcUtil.exe against the .svc file for the web service. I am not sure if this has anything to do with it or not but wanted to document this in case.

Does anyone have any suggestion or seen this before where it runs fine in "debug mode" but fails in "release mode"?

Thank you!

Answer Source

I`ve just run into the same problem in release compilation of my project. After awhile of wandering around I set internet permission on in ProjectOptions->AndroidApplication->Required permissions (in Xamarin studio). It looks working for me

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download