6
votes

I've created a Xamarin.Forms project with .netstandard 2.0 as PCL project. I'm trying to consume WCF services in that project. I've added the connected service for WCF service. When I'm trying to call any method provided in the service, it gives the error as below:

System.ServiceModel.FaultException`1[[System.ServiceModel.ExceptionDetail, System.ServiceModel, Version=2.0.5.0, 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/'

I've also tried to change the .netstandard version to an older version but it gives the same error.

2
The error suggests the shape of the body is incorrect, rather than a method not implemented. Are the models correct? - Neil
@Neil yes the models are correct. Actually the method GetData may have the problem with the proxy classes generated by the WCF service provider in Visual Studio - vishgarg
Hi there! Does anyone know if Xamarin will be compatible with Task-based asynchronous WCF proxy methods? Thanks in advanced. - Ignacio
@Ignacio I think it'll take time as there is no news for its implementation for now. - vishgarg

2 Answers

7
votes

At the moment Xamarin apps aren't compatible with the Task-based asynchronous WCF proxy methods that the WCF Web Service Reference connected service provider generates for .NET Standard projects (bugzilla.xamarin.com Bug 51959).

One way to generate an older, compatible style of WCF proxy methods is to run SvcUtil.exe with the /async and /tcv:Version35 switches in a Developer Command Prompt. That will generate synchronous proxy methods, Begin/End style Asynchronous Programming Model (APM) callback proxy methods, and event-based proxy methods, all of which are compatible with Xamarin apps.

(Note: If you leave out the /async switch, SvcUtil.exe will generate the newer, incompatible Task-based proxy methods.)

3
votes

Generate an older compatible style of WCF proxy methods via checked "Generate Synchronous Operations" checkbox on Configure WCF Web Service Reference screen:

Generate Synchronous Operations

Consume the web service:

KimlikServiceReference.KPSPublicSoapClient soapClient = new KimlikServiceReference.KPSPublicSoapClient(KimlikServiceReference.KPSPublicSoapClient.EndpointConfiguration.KPSPublicSoap);
//KimlikServiceReference.TCKimlikNoDogrulaResponse response = soapClient.TCKimlikNoDogrulaAsync(TCKimlikNo, Ad, Soyad, DogumYili).Result;
bool result = soapClient.TCKimlikNoDogrula(TCKimlikNo, Ad, Soyad, DogumYili);