Mono/Xamarin iOS - ipv6 problems

Hello everyone,

our App got rejected by Apple today because it is not working with ipv6. After a bit of research i have the feeling that it comes down to WinInetHttpClientChannel.

We have the following setup:
Xamarin iOS project. The iOS project references a project where we have all references to RemObjects libraries etc. To reproduce the problem be sure that the device is in an ipv6 environment. (Supporting IPv6 DNS64/NAT64 Networks → Test for IPv6 DNS64/NAT64 Compatibility Regularly)

Inside we do the following:

private ClientChannel CreateChannel(Uri uri)
{
var channel = new WinInetHttpClientChannel();
channel.TargetUrl = uri.ToString();
if (CompatibilitySettings.RemObjectsIncreaseTimeout)
channel.Timeout = 120;
return channel;
}

If i pass “http://192.68.xxx.xxx:80/BIN” as uri i get the following on the first usage of the channel:

SocketException: Network is unreachable
at System.Net.Sockets.Socket.Connect (System.Net.EndPoint remoteEP) [0x000cb] in /Users/builder/data/lanes/3859/b638977c/source/xamarin-macios/_ios-build/Library/Frameworks/Xamarin.iOS.framework/Versions/git/src/mono/mcs/class/System/System.Net.Sockets/Socket.cs:1313
at System.Net.WebConnection.Connect (System.Net.HttpWebRequest request) [0x001c2] in /Users/builder/data/lanes/3859/b638977c/source/xamarin-macios/_ios-build/Library/Frameworks/Xamarin.iOS.framework/Versions/git/src/mono/mcs/class/System/System.Net/WebConnection.cs:195

WebException: Error: ConnectFailure (Network is unreachable)
at RemObjects.SDK.WinInetHttpClientChannel+AsyncState.get_Message () [0x0004e] in <43f87e2f3b25489f93e661a67852e8d3>:0
at RemObjects.DataAbstract.Server.SimpleLoginService_AsyncProxy.EndLogin (System.IAsyncResult __AsyncResult, RemObjects.DataAbstract.Server.UserInfo& aUserInfo) [0x00000] in <903f7027d1af4524a3fb11501a3f4c6c>:0
at RemObjectsServices.LoginService.m__0 (System.IAsyncResult r) [0x00005] in /Users/RemObjectsServices/LoginService.cs:32
at System.Threading.Tasks.TaskFactory1[TResult].FromAsyncCoreLogic (System.IAsyncResult iar, System.Func2[T,TResult] endFunction, System.Action1[T] endAction, System.Threading.Tasks.Task1[TResult] promise, System.Boolean requiresSynchronization) [0x00014] in :0

If i pass a normal URL like “https://mobile.xxx.com:1625/BIN” it works. I also tried to transform my ip4 address to ipv6 but same result.

Can you tell me how this should work? Does the flag in the iOS build settings of the Xamarin project influence that? (HttpClient implementation)?

Any help would be appreciated. I am completely stuck here.

Thank you!

Hello

Unlike Ip-.… channels family WinInetHttpClientChannel is a wrapper over the HttpWebRequest instance.
Please contact Xamarin support why WebRequest created as

(HttpWebRequest)WebRequest.Create(this.TargetUri)

cannot connect to the server. F.e. I see the same stacktrace in this Xamarin forum post: https://forums.xamarin.com/discussion/78286/problem-connect-webapi-crm-in-xamarin-forms-ios10

Hello antonk,

thank you for your quick response. You are right, the WebRequest code also does not work with an ipv4 from Xamarin at the moment, which should not be the case. Looks like a bug there.

However

It would be much better to have the channel working with HttpClient instead of WebRequest since that seems to be the future.

Also in Xamarin you can only use the native network options (NSURLSession on iOS) over Httpclient. For example this is the only way to support TLS 1.2 which could always be a requirement by customers. Also, the performance with the HttpClient based solution is much better.

The way how to inject different handlers for network requests is:

public HttpClient (HttpMessageHandler handler);
HttpClient a = new HttpClient(new NSUrlSessionHandler());

By that the handler and clients are decoupled. I think it would be great and even necessary for RemObjects to support this if you want to support Xamarin in the future.

Thank you for your help! Let me know in case I should post this to anyone else or provide information for a possible feature request!

Hello

I’ve seen a response on Xamarin forum that they have released a fix for it in the latest release.

You’re right, HttpClient would be a better solution. Unfortunately it is not supported in PCL we use to support Xamarin.
Still some more investigation and research are needed. Please drop a mail to support@ so we’ll be able to contact you once we have a solution (we’ll ask you to test it ‘in the wild’).

After we have a solution I’ll post it in this thread too for further reference.

Regards

Hello

Still some more investigation and research are needed. Please drop a mail to support@ so we’ll be able to contact you once we have a solution (we’ll ask you to test it ‘in the wild’).

Thanks in advance

Please take a look at HttpClient-based Client Channel for Xamarin platforms (and other platforms supported via PCL)