Search code examples
wcfxamarinasync-awaituwpnavision

WCF - call a function with await key throws an exception


I get the following error:

This IRandomAccessStream does not support the GetInputStreamAt method because it requires cloning and this stream does not support cloning.

My customer runs an test azure webservice of microsoft nav server.

SOAP is my Service Reference

ISoapService.cs

public interface ISoapService
{
    Task<string> ShipGetNewBatchCode(string macAddress);
}

SoapService.cs

public class SoapService : ISoapService
{
    private SOAP.scan_PortClient soapClient;

    public SoapService()
    {
        ConfigurateSoapService();
    }

    public async Task<string> ShipGetNewBatchCode(string macAddress)
    {
        var retValue = "";

        try
        {
            var response = await soapClient.ShipGetNewBatchCodeAsync(macAddress);
            retValue = response.return_value;
        }
        catch (Exception ex)
        {
            Debug.WriteLine(@"              ERROR {0}", ex.Message);
        }

        return retValue;
    }

    private void ConfigurateSoapService()
    {
        var timespan = new TimeSpan(0, 1, 0);
        var binding = new BasicHttpBinding();
        var uri = new Uri("http://***aka.westeurope.cloudapp.azure.com:*2/**/**/****/**/***");
        var endpoint = new EndpointAddress(uri);

        binding.Name = "scan_Binding";
        binding.CloseTimeout = timespan;
        binding.OpenTimeout = timespan;
        binding.ReceiveTimeout = timespan;
        binding.SendTimeout = timespan;
        //binding.AllowCookies = false;
        ///binding.BypassProxyOnLocal = false;
        //binding.HostNameComparisonMode = HostNameComparisonMode.StrongWildcard;
        binding.MaxBufferPoolSize = 524288;
        binding.MaxReceivedMessageSize = 65536;
        //binding.MessageEncoding = WSMessageEncoding.Text;
        binding.TextEncoding = Encoding.UTF8;
        //binding.UseDefaultWebProxy = true;

        binding.ReaderQuotas.MaxDepth = 32;
        binding.ReaderQuotas.MaxStringContentLength = 8192;
        binding.ReaderQuotas.MaxArrayLength = 16384;
        binding.ReaderQuotas.MaxBytesPerRead = 4096;
        binding.ReaderQuotas.MaxNameTableCharCount = 16384;

        binding.Security.Mode = BasicHttpSecurityMode.TransportCredentialOnly;
        binding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Windows;

        soapClient = new SOAP.scan_PortClient(binding, endpoint);
        soapClient.ClientCredentials.Windows.ClientCredential = new System.Net.NetworkCredential("****", "*****");
    }
}

ViewModel Class

var soapService = DependencyService.Get<ISoapService>();
var a = await soapService.ShipGetNewBatchCode("11");

Solution

  • I Solved this problem by deleting the following reference:

    Visual C++ 2015 Runtime for Universal Windows Platform Apps

    and I updated

    Microsoft.NETCore.UniversalWindowsPlatform

    to version v5.2.2