xamarin / xamarin-macios

.NET for iOS, Mac Catalyst, macOS, and tvOS provide open-source bindings of the Apple SDKs for use with .NET managed languages such as C#
Other
2.49k stars 515 forks source link

Connect to WCF Service from Xamarin IOS #10737

Closed akranz closed 3 years ago

akranz commented 3 years ago

Hi,

I´m trying to connect to WCF services from an application made by Xamarin ios (nor forms) and I´m getting this message when I´m trying to do it:

"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.ChannelFactory"

I´ve read so many articles, forums... where it says that I have to override CreateClient method but I do not have this method inside my .svc, because I call it from ChannelFactory.

Do you have any ideas to make this work properly or WCF is 100% dead on ios? By the way, on android is working fine.

Steps to Reproduce

Having WCF service and, after putting my credentials, the error happen on CreateClient inside ChannelFactory

Expected Behavior

Return Client correctly

Actual Behavior

Environment

Visual Studio 2019 Xamarin iOS On Emulator ios sdk 14.4

Build Logs

Example Project (If Possible)

mandel-macaque commented 3 years ago

Hello, this is not a support forum for API usage, as the exception says the dynamic generation does not work. The iOS projects are AOT and do not have dynamic code execution. Nevertheless, what I believe you have to do is not to use the generic code:

return (factory as ChannelFactory<TClient>).CreateChannel();

But extend from the ChannelFactory class and override the virtual method: https://docs.microsoft.com/en-us/dotnet/api/system.servicemodel.channelfactory-1.createchannel?view=dotnet-plat-ext-5.0#System_ServiceModel_ChannelFactory_1_CreateChannel

Override the method and just call it. You can look at the ref implementation here: https://github.com/microsoft/referencesource/blob/master/System.ServiceModel/System/ServiceModel/ChannelFactory.cs#L677