WCF error on Windows 10 mobile universal app

518 views Asked by At

Have a Windows 10 Mobile app that needs to make calls to a WCF service. This is an existing service, running on another server (c#/IIS) and I can connect to the service just fine and make calls from my Xamarin.Android app, using the following code:

    public PacTracMobileServerClient GetClient()
    {
        var config = new Config.AppConfig();
        var serverUrl = config.GetODSServerAddress;

        var binding = new CustomBinding();
        //TODO: Make these timeouts configurable
        binding.SendTimeout = TimeSpan.FromMinutes(2);
        binding.ReceiveTimeout = TimeSpan.FromMinutes(2);

        var tme = new TextMessageEncodingBindingElement(MessageVersion.Soap11, Encoding.UTF8);
        binding.Elements.AddRange(tme);

        if (serverUrl.StartsWith("https", StringComparison.CurrentCultureIgnoreCase))
        {
            //HTTPS binding
            var https = new HttpsTransportBindingElement
            {
                MaxReceivedMessageSize = int.MaxValue,
                MaxBufferSize = int.MaxValue,
                RequireClientCertificate = false,
            };
            binding.Elements.Add(https);

            //Trust all certificates
            //ServicePointManager.ServerCertificateValidationCallback = delegate (object s, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors) { return true; };
        }
        else
        {
            //HTTP binding
            var http = new HttpTransportBindingElement
            {
                MaxReceivedMessageSize = int.MaxValue,
                MaxBufferSize = int.MaxValue
            };
            binding.Elements.Add(http);
        }

        var endPoint = new EndpointAddress(new Uri(serverUrl));

        return new PacTracMobileServerClient(binding, endPoint);
    }

Again, the above is working in Xamarin.Android (although I will be happy to improve on it if there are suggestions). Since my Xamarin.Android implementation was .Net, I was hoping it just working with this Windows UWP app. Everything seems to be fine except for the line that was commented out for trusting all certificates as it seems ServicePointManager is not supported in UWP?

All that said, I am getting the following error when I try to make a call using this client in my UWP app

net_http_client_execution_error

So, two questions.

  1. What is wrong with my code above and how can I change it to work with my UWP app so I can call the WCF service?

  2. I am wondering if my issue is because of the certificates as the only difference between Android (working) and UWP (not working) is the line I had to comment out for the ServicePointManager. How can I implement something similar for UWP? Basically, this app is only used internally and I don't want or need to worry about certificates when calling the service.

Note: I did make sure to enable capabilities for Internet (Client & Server), Internet (Client) and Private Networks (Client & Server) in my package manifest. Also, I did verify I am connected to the network and can access the service from the web browser on the mobile device.

Thanks!

0

There are 0 answers