Castle Windsor の優れた wcf 機能を使用して、クライアント プロキシを作成しようとしています。ただし、カスタム プロパティを追加する機能を利用する場合、OperationContextScope にアクセスする必要があります。私のアプローチは実行時に次のエラーで失敗します:無効な IContextChannel が OperationContext に渡されました。サーバー ディスパッチ チャネルまたはクライアント プロキシ チャネルのいずれかである必要があります。これは、以下に示すように、コードが 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);
}
}