我正在尝试使用 Castle Windsor 中出色的 wcf 设施创建客户端代理。但是,在使用该工具添加自定义属性时,我需要访问 OperationContextScope。我的方法在运行时失败并出现以下错误:传递给 OperationContext 的 IContextChannel 无效。必须是服务器调度通道或客户端代理通道。当代码进入 using 块时会发生这种情况,如下所示。非常感谢有关如何完成这项工作的任何建议。
容器设置:
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());
}
}
调用代理:
[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);
}
}