I am trying to call methods on a web service using delegate calls:
public IEnumerable<MyDataType> List(bool showDeleted)
{
var result = ResponseHelper<dynamic[], IEnumerable<MyDataType>>(new dynamic[] {InstanceGuid, showDeleted}, "List");
return result;
}
public MyDataType Get(int myDataTypeId, bool showDeleted)
{
var result = ResponseHelper<dynamic[], MyDataType>(new dynamic[] {InstanceGuid, myDataTypeId, showDeleted}, "Get");
return result;
}
public static R ResponseHelper<T, R>(T parameters, string serviceAction)
{
var results = default(R);
foreach (var service in _webServiceCoordinator.GetServices())
{
var func = (Func<T, R>)Delegate.CreateDelegate(typeof(Func<T, R>), service, serviceAction);
try
{
results = func(parameters);
break;
}
catch
{
_webServiceCoordinator.LastServiceFaulted();
}
}
return results;
}
The method _webServiceCoordinator.GetServices()
returns an IEnumerable of
System.Runtime.Remoting.Proxies.__TransparentProxy
containing services of this contract:
public interface IOverrideService : IWebService
{
IEnumerable<MyDataType> List(Guid instanceGuid, bool showDeleted);
MyDataTypeGet(Guid instanceGuid, int myDataTypeId, bool showDeleted);
}
The error I receive at the Delegate.CreateDelegate
line is:
Cannot bind to the target method because its signature or security transparency is not compatible with that of the delegate type.
My thoughts are it's failing because it's a delegate of a proxy class, but (in my mind) a pointer of a pointer should still work.
I wondered if it was related to this question, even though I get a different error message.
It is a .Net 4.0 project, but I am using VS2012 (so have .NET 4.5 installed)