I am trying to intercept a WCF client. But the Unity interceptor does not seem to work.
- I am not getting a call to the proxy.
- I did not know how to link the attribute to the container
- In AddPolicy what is the name attribute - Here I used the function to intercept - GetXml.
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Method)]
public class GetXmlCallHandlerAttribute : HandlerAttribute
{
public GetXmlCallHandlerAttribute(){}
public override ICallHandler CreateHandler(IUnityContainer ignored)
{
return new GetXmlTestCallHandler();
}
}
public class GetXmlTestCallHandler : ICallHandler
{
public int Order { get; set; }
public IMethodReturn Invoke(IMethodInvocation input, GetNextHandlerDelegate getNext)
{
IMethodReturn msg;
Object returnValue = XElement.Load("../../Resources/a1.xml");
Object[] outputs = null;
msg = input.CreateMethodReturn(returnValue, outputs);
return msg;
}
}
class SendDataTest
{
public void GetXmlTest()
{
IUnityContainer container = new UnityContainer();
ICallHandler myInterception = new GetXmlTestCallHandler();
container.AddNewExtension<Interception>();
container.RegisterType<SendData>(new Interceptor(new TransparentProxyInterceptor()));
container.Configure<Interception>().AddPolicy("GetXml").AddCallHandler(myInterception);
SendData target = container.Resolve<SendData>();
XElement expected = null; // TODO: Initialize to an appropriate value
XElement actual;
actual = target.GetXml();
Assert.AreEqual(expected, actual);
Assert.Inconclusive("Verify the correctness of this test method.");
}
}