Search code examples
c#wcfxamarin.ios

Struggling to override System.ServiceModel.ClientBase<T>.CreateChannel()


I am getting the following InvalidOperationException while implementing a MonoTouch client for a simple WCF service exposed over HTTP.

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

That comes from line 141 in this file.

So I need to override the method CreateChannel() on System.ServiceModel.ClientBase<T> in my own subclass of ClientBase with an implementation that does not use dynamic code generation. The method returns an instance of T.

If I return a new instance of my service client, System.ServiceModel.ClientBase<T> throws the exception Unable to cast object of type 'MyServiceClient' to type 'System.ServiceModel.IClientChannel' on the getter for InnerChannel.

I have no clear idea how to proceed from this point - any pointers appreciated.


Solution

  • This was a very simple interface - so I just wrote a simple client based on System.Net.WebClient, which worked perfectly and was about 10 lines of code.