Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't call WCF methods in Xamarin.Forms (Cross-Platform) #2940

Closed
AliParLouS opened this issue Jun 12, 2018 · 12 comments
Closed

Can't call WCF methods in Xamarin.Forms (Cross-Platform) #2940

AliParLouS opened this issue Jun 12, 2018 · 12 comments
Labels
Xamarin Issues pertaining to Xamarin.

Comments

@AliParLouS
Copy link

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=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/'

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.

@TillAlex
Copy link

Under iOS you can't use dynamic proxy generation. Here is an example for implementing how to get a client with iOS:

https://forums.xamarin.com/discussion/15148/how-to-access-wcf-service-in-ios-platform-using-xamarin

@AliParLouS
Copy link
Author

@TillAlex I checked the link and couldn't find even where should i put those code to get working. Right now my project create a Reference.cs in a folder with name ServiceReference1 under Connected Services. I should say this is a auto generate file even i change it, It will back to normal if i update my WCF connection in case i republish my web service on web.

@TillAlex
Copy link

Sorry, I do not have any experience with autogenerated clients, but it seems they use dynamic proxy generation. We were able to implement a client ourselves (manually) the way it is done in that thread and it's working with iOS.

@Lxiamail
Copy link
Member

duplicate of #2463

@Lxiamail Lxiamail added the Xamarin Issues pertaining to Xamarin. label Jun 21, 2018
@AliParLouS
Copy link
Author

dear @Lxiamail you closed this issue and show me a similar issue #2463 but even there, still there is no solution for this. By the way that issue maybe even not similar to mine, i include 2 error in my question and even my 2 errors are different than him

@musab-alrmmah
Copy link

this same my problem . what solution for this issue? @AliParLouS

@musab-alrmmah
Copy link

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

at System.ServiceModel.ChannelFactory1[TChannel].CreateChannel (System.ServiceModel.EndpointAddress address, System.Uri via) [0x00000] in /Library/Frameworks/Xamarin.iOS.framework/Versions/12.0.0.15/src/Xamarin.iOS/mcs/class/System.ServiceModel/System.ServiceModel/ChannelFactory_1.cs:141 at System.ServiceModel.ChannelFactory1[TChannel].CreateChannel (System.ServiceModel.EndpointAddress address) [0x00000] in /Library/Frameworks/Xamarin.iOS.framework/Versions/12.0.0.15/src/Xamarin.iOS/mcs/class/System.ServiceModel/System.ServiceModel/ChannelFactory_1.cs:115
at System.ServiceModel.ChannelFactory1[TChannel].CreateChannel () [0x00006] in /Library/Frameworks/Xamarin.iOS.framework/Versions/12.0.0.15/src/Xamarin.iOS/mcs/class/System.ServiceModel/System.ServiceModel/ChannelFactory_1.cs:110 at System.ServiceModel.ClientBase1[TChannel].CreateChannel () [0x00000] in /Library/Frameworks/Xamarin.iOS.framework/Versions/12.0.0.15/src/Xamarin.iOS/mcs/class/System.ServiceModel/System.ServiceModel/ClientBase.cs:266
at System.ServiceModel.ClientBase1[TChannel].get_InnerChannel () [0x00008] in /Library/Frameworks/Xamarin.iOS.framework/Versions/12.0.0.15/src/Xamarin.iOS/mcs/class/System.ServiceModel/System.ServiceModel/ClientBase.cs:186 at System.ServiceModel.ClientBase1[TChannel].get_Channel () [0x00000] in /Library/Frameworks/Xamarin.iOS.framework/Versions/12.0.0.15/src/Xamarin.iOS/mcs/class/System.ServiceModel/System.ServiceModel/ClientBase.cs:192

this description for this error

@TillAlex
Copy link

TillAlex commented Oct 7, 2018

With iOS dynamic proxy generation does not work. See my first post in this issue.

@musab-alrmmah
Copy link

@TillAlex How to use this code in xamarin forms project ?

@AliParLouS
Copy link
Author

this same my problem . what solution for this issue? @AliParLouS

So far nothing, Still WCF not work in iOS and Android for me, I changed my WCF to WebAPI for now, But it's not a solution...

@TillAlex
Copy link

TillAlex commented Oct 8, 2018

@musab-alrmmah: Did you try to implement your own ServiceChannel deriving from ChannelBase<> and a Servive overriding CreateChannel like it is described in the post I am linking?

@KonstantinosP7
Copy link

I have exactly the same issue, WCF is returning value only in UWP but NOT in Android or IOS. Any solution?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Xamarin Issues pertaining to Xamarin.
Projects
None yet
Development

No branches or pull requests

5 participants