c# - Create Dynamic Delegate WCF TransparentProxy -
I am trying to write the general method that all wcf proxy methods go through this method and through the cache return value Go. Generic method
Public T service service & lt; T & gt; (Rep. Della, Object [] args) {// Caching Logic // // // If the price is cached, then return it. Otherwise call the app site. // end caching logic return (t) del.DynamicInvoke (args); }
To achieve this, I would have to dynamically make a representation with the help of the following link
In short, what do I want to channel The method is to create the representative for IFooService.Bar (String Ultimate).
// wcf contract public interface iFooService {int bar (string absolute); } // sample proxy public class Foo {public int bar (string absolute) {IFooService channel = zero; Full result; {// We believe that the wcf channel made here is the Channel Factor & lt; IFooService & gt; ChannelFactory = New Channel Factor & lt; IFooService & gt; (Binding, remote address); IFooService Channel = channelFactory.CreateChannel (); Var parameter = methodebase GetCurrentMethod (). GetParameters (); Object [] args = new object [parameter. Length]; Argus [0] = the ultimate; MethodInfo method = typeof (IFooService) .GetMethod ("bar"); Representative Dela = CreateDeliget (channel, method); Results = Callservity & lt; Int & gt; (Del, args); (ICommunicationObject) channel .close (); } Grip (Exceptional) {((Information Communication Channel)) .bort (); throw; } Return results; }}
When the application runs, I get the exception "on the geometry del = CreateDelegate (channel, method)".
The target method can not be compelled because its signature or security transparency is not compatible with the representative type on the system. Delegate.CreateDelegate (type type, object firstarm, MethodInfo method, boolean thrownbandfileer)
I believe the method signature is correct.
The exact type of channel object is System.Runtime.Remoting.Proxies.__transparentProxy . However, the channel .getType () returns IFooService how is this possible? What is the magic behind this situation? I wonder how Pattern provides this solution and how __transporpcxi works. Does any code (project) sample show this architecture? I think this is the reason why dynamic reproduction could not force the target method.
When I tried, I got the same exception
MethodInfo Mi = typeof (IMyInterf) .GetMethod (MyMethod); Representative D = Representative Prepare (type (myMethodDelegate), channels, miles); D.DynamicInvoke (args);
This works when I change it on:
Representative D = Rep. Prepare (type (myMethodDelegateX), faucet, mi); D.DynamicInvoke (channel, args);
If myMethodDelegate looks like this
zero myMethodDelegate Representative (T1 arg1, T2 arg2, ...);
Then there should be example parameter in myMethodDelegateX for which you pass the channel as the first argument, after the actual method arguments, according to the dynamic invocation call:
Assign my Mathematlegate X (IMI Interface Target Instruction, T1 AGR1, T2 RG2, ...);
I found this version in milligram in MSDN documentation. Creative (type, object, method infow) overload, it is called an "open instance" method there, and it can not be forced to target my WCF channel, where I always found "method ..." / P>
Edit: Absolutely d.DynamicInvoke (channel, args) is nonsense, you have to keep these arguments in a new array. / P>
Comments
Post a Comment