我正在尝试使用委托调用来调用Web服务上的方法:
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;
}
方法_webServiceCoordinator.GetServices()
返回IEnumerable
System.Runtime.Remoting.Proxies.__TransparentProxy
包含此合同的服务:
public interface IOverrideService : IWebService
{
IEnumerable<MyDataType> List(Guid instanceGuid, bool showDeleted);
MyDataTypeGet(Guid instanceGuid, int myDataTypeId, bool showDeleted);
}
我在Delegate.CreateDelegate
行收到的错误是:
Cannot bind to the target method because its signature or security transparency is not compatible with that of the delegate type.
我的想法是失败的,因为它是代理类的委托,但(在我看来)指针的指针应该仍然有效。
我想知道它是否与此question有关,即使我收到了不同的错误消息。
这是一个.Net 4.0项目,但我使用的是VS2012(安装了.NET 4.5)