I am facing a problem from the past few days : I struggle to understand what I need to implement in my Xamarin client to avoid WCF service proxy code generation on iOS.
From what I’ve found on https://github.com/xamarin/xamarin-macios/issues/10737, I need to override base TChannel creation method from ChannelFactory<TChannel> that is using dynamic code generation.
So I started to override this method by simply returning a new instance of the TChannel I needed :
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Tools.ServiceModel.Svcutil", "2.1.0")]
public partial class MySoapServiceClient : System.ServiceModel.ClientBase<MySoapService>, MySoapService
{
protected override MySoapService CreateChannel()
{
return new MySoapServiceClient(EndpointConfiguration.MyEndpointConfiguration);
}
public MySoapServiceClient(EndpointConfiguration endpointConfiguration) :
base(MySoapServiceClient.GetBindingForEndpoint(endpointConfiguration), MySoapServiceClient.GetEndpointAddress(endpointConfiguration))
{
this.Endpoint.Name = endpointConfiguration.ToString();
ConfigureEndpoint(this.Endpoint, this.ClientCredentials);
}
}
Here is an example of request implemented :
[System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Tools.ServiceModel.Svcutil", "2.1.0")]
[System.ServiceModel.ServiceContractAttribute(Namespace="http://myapiservice.com/", ConfigurationName="MyNamespace.MySoapService")]
public interface MySoapService
{
[System.ServiceModel.OperationContractAttribute(Action="http://myapiservice.com/GetSessionId", ReplyAction="*")]
[System.ServiceModel.XmlSerializerFormatAttribute(SupportFaults=true)]
System.Threading.Tasks.Task<string> GetSessionIdAsync(string user, string pwd);
}
What I can’t find out is : the getter of my ClientBase.Channel which calls this CreateChannel method throws an InvalidCastException (I think it must be at the
return (TChannel)ServiceChannelFactory.CreateChannel<TChannel>(address, via);
from ChannelFactory<TChannel>.CreateChannel(EndpointAddress address, Uri via)).
I’m new to web services and I don’t understand what my MySoapServiceClient needs to implement to be able to be casted from this method, could anyone clarify what exactly ChannelFactory.CreateChannel needs ?