Reputation: 98
I am trying to create client proxies using the excellent wcf facility in Castle Windsor. However, I need to access the OperationContextScope when utilizing the facility to add a custom property. My approach fails at runtime with the following error: Invalid IContextChannel passed to OperationContext. Must be either a server dispatching channel or a client proxy channel. This happens when the code enters the using block as shown below. Any advice on how to make this work is greatly appreciated.
Container setup:
public class WcfClientInstaller : IWindsorInstaller
{
public void Install(IWindsorContainer container, IConfigurationStore store)
{
container.AddFacility<WcfFacility>();
container.Register(Component.For<IMyInterface>().AsWcfClient(new DefaultClientModel
{
Endpoint = WcfEndpoint.FromConfiguration("MyEndpoint"),
}).LifestyleTransient());
}
}
Invoking the proxy:
[Test]
public void Test()
{
var container = new WindsorContainer();
container.Install(new WcfClientInstaller());
var proxy = container.Resolve<IMyInterface>();
// Crashes here
using (new OperationContextScope((IContextChannel)proxy))
{
var bmp = new BrokeredMessageProperty { CorrelationId = "someNonStaticId" };
OperationContext.Current.OutgoingMessageProperties.Add(BrokeredMessageProperty.Name, bmp);
}
}
Upvotes: 0
Views: 248