View Full Version : Wrapping a WCF Proxy
Hello,
I'm trying to do the following:
IService1 = ... < obtain wcf proxy > ...
ProxyFactory factory = new ProxyFactory(proxy);
//... add advisors here, etc ...
IService1 springProxy = (IService1)factory.GetProxy();
But after trying to execute the last line to finally get the proxy, an exception is thrown:
Could not load type 'DecoratorAopProxy_32413d4325444047b1f604a98cec22f 5' from assembly 'Spring.Proxy, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null' because the parent type is an interface.
The problem may be obvious to some, but since I am a starter I hope you understand.
Is it possible to do what I'm trying to perform here? I want to be able to do it just like that, programatically....
Thank you very much.
Bruno Baia
12-06-2007, 06:20 PM
Hi,
WCF proxies are transparent proxies, you have to indicate to the ProxyFactory which interface you want to proxy :
ProxyFactory factory = new ProxyFactory(proxy);
factory.AddInterface(typeof(IService1));
...
HTH,
Bruno
Thanks Bruno!
Just one problem... I added the interface like you said, but I still get an exception:
IService1 proxy = ...<obtain wcf proxy>...
ProxyFactory factory = new ProxyFactory(proxy);
factory.AddInterface(typeof(IService1));
factory.AddAdvice(new ConsoleLoggingAdvice());
IService1 proxy2 = (IService1)factory.GetProxy();
The last line (GetProxy) gives me the exeption "'this' type cannot be an interface itself.".
This is the stack trace
System.ArgumentException was unhandled
Message="'this' type cannot be an interface itself."
Source="mscorlib"
StackTrace:
at System.RuntimeTypeHandle.GetFirstSlotForInterface( IntPtr interfaceHandle)
at System.RuntimeTypeHandle.GetFirstSlotForInterface( RuntimeTypeHandle interfaceHandle)
at System.RuntimeType.GetInterfaceMap(Type ifaceType)
at Spring.Proxy.AbstractProxyTypeBuilder.GetInterface Mapping(Type targetType, Type intf)
at Spring.Proxy.AbstractProxyTypeBuilder.ImplementInt erface(TypeBuilder typeBuilder, IProxyMethodBuilder proxyMethodBuilder, Type intf, Type targetType, Boolean proxyVirtualMethods)
at Spring.Proxy.AbstractProxyTypeBuilder.ImplementInt erface(TypeBuilder typeBuilder, IProxyMethodBuilder proxyMethodBuilder, Type intf, Type targetType)
at Spring.Aop.Framework.DynamicProxy.CompositionAopPr oxyTypeBuilder.BuildProxyType()
at Spring.Aop.Framework.DynamicProxy.CachedAopProxyFa ctory.BuildProxyType(IProxyTypeBuilder typeBuilder)
at Spring.Aop.Framework.DynamicProxy.DefaultAopProxyF actory.CreateAopProxy(AdvisedSupport advisedSupport)
at Spring.Aop.Framework.AdvisedSupport.CreateAopProxy ()
at Spring.Aop.Framework.ProxyFactory.GetProxy()
at SmartChannelTest.Program.Main(String[] args) in C:\Projectz\SmartChannel\SmartChannel\SmartChannel Test\Program.cs:line 221
at System.AppDomain.nExecuteAssembly(Assembly assembly, String[] args)
at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.Run UsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context( Object state)
at System.Threading.ExecutionContext.Run(ExecutionCon text executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
BTW, I'm using the 1.1-RC2 release.
Any ideas?
Regards.
Bruno Baia
12-06-2007, 08:05 PM
How do you get the service instance ?
Something like that ?
IService1 proxy = ChannelFactory<IService1>("Service1").CreateChannel()
I could reproduce the problem, I'm investigating...
- Bruno
Hi Bruno,
I'm creating the WCF proxy with a somewhat customized ChannelFactory<T> that obtains information from the target service's metadata.... but at the end the result is the same, it creates you the same WCF transparent proxy, the type is __TransparentProxy.
Good to know that you reproduced it... hope there's a viable solution.
Bruno Baia
12-07-2007, 07:39 PM
Hi,
Fixed ! This was the latest bug resolved in 1.1 Final release that will be out in the next hours...
I don't know if this is a fixed bug or a new feature, because the problem is that calling GetType() on a WCF proxy instance returns an interface type.
instance.GetType() returning interface type is not really clear imo...
Anyway, your initial code should work now :
IService1 = ... < obtain wcf proxy > ...
ProxyFactory factory = new ProxyFactory(proxy);
//... add advisors here, etc ...
IService1 springProxy = (IService1)factory.GetProxy();
- Bruno
vBulletin® v3.7.3, Copyright ©2000-2008, Jelsoft Enterprises Ltd.