Can't call WCF methods in Xamarin.Forms (Cross-Platform) RRS feed

  • Question

  • User367994 posted

    Hi, I just create a simple WCF project with default values (without change even a single line of code), i publish it in web, Consume it in EXE application and it work fine, Cosume it in asp.net webform and it work fine.

    Now i create another simple Xamarin Cross-Platform with .Net Standard 2 (UWP, iOS, Android), Used "Microsoft WCF Web Service Reference Provider" and i checked all 3 project in UWP work fine but in android and iOS project load and after click the button can't call GetDataAsync().

    Xamarin button clicked code :

    Service1Client client = new Service1Client(Service1Client.EndpointConfiguration.BasicHttpsBinding_IService1); string returnString; returnString = await client.GetDataAsync(Convert.ToInt32(entNumber.Text)); lblResult.Text = returnString; await client.CloseAsync();

    Android runtime error after clicked button :

    Unhandled Exception: System.ServiceModel.FaultException`1[[System.ServiceModel.ExceptionDetail, System.ServiceModel, Version=, Culture=neutral, PublicKeyToken=31bf3856ad364e35]]: Error in deserializing body of request message for operation 'GetData'. OperationFormatter encountered an invalid Message body. Expected to find node type 'Element' with name 'GetData' and namespace 'http://tempuri.org/'. Found node type 'Element' with name 'GetDataAsync' and namespace 'http://tempuri.org/'

    iOS runtime error after clicked button :

    Unhandled Exception: System.InvalidOperationException: MonoTouch does not support dynamic proxy code generation. Override this method or its caller to return specific client proxy instance

    Funny thing is UWP work fine and return method string just fine. This is my first experience to consume WCF in xamarin.forms and i feel maybe i do something wrong.

    Friday, June 15, 2018 10:57 AM

All replies

  • User21936 posted


    There are some limitations with WCF in Mono/Xamarin. Some WCF bindings are unsupported and some methods of proxy generation may not work. This is because of a couple of reasons: 1) mono does not fully support WCF and 2) Xamarin.iOS and Xamarin.Android only use a subset of .NET, though they do conform to .NET Standard 2.0.

    Please go over these guides on working with WCF and Xamarin: Forms: https://docs.microsoft.com/en-us/xamarin/xamarin-forms/data-cloud/consuming/wcf Xamarin native (non-Forms): https://docs.microsoft.com/en-us/xamarin/cross-platform/data-cloud/web-services/walkthrough-working-with-wcf

    Friday, June 15, 2018 7:15 PM
  • User74518 posted

    WCF is dead. Switch to ASP.NET Core WebApi, and you will be more happier.

    Saturday, June 16, 2018 10:47 AM