IIS asp.net ihttpmoduleからのWCFチャネルを使用します
-
27-10-2019 - |
質問
カスタムIHTTPMODULEを使用するASP.NETプロジェクトがあります。このモジュールはパイプラインに配置され、特定の基準が一致する場合、同じマシンの単純なC#コンソールアプリケーションでホストされているWCFサービスのメソッドを呼び出す必要があります。
モジュールのコードは次のとおりです。
using System;
using System.Collections.Generic;
using System.Text;
using System.Web.SessionState;
using System.Web;
using System.Diagnostics;
using System.IO;
using System.Runtime.Serialization.Formatters.Binary;
using System.Configuration;
using System.ServiceModel;
using SimpleFarmStateServer;
namespace SimpleFarm
{
public class SimpleFarmModuleSS : IHttpModule, IRequiresSessionState
{
protected string cache_directory = "";
// WCF
ChannelFactory<IStateServer> factory;
IStateServer channel;
public void Dispose() { }
public void Init(System.Web.HttpApplication context)
{
context.PreRequestHandlerExecute += new EventHandler(context_PreRequestHandlerExecute);
setupFactory();
}
void setupFactory()
{
factory = new ChannelFactory<IStateServer>(
new NetNamedPipeBinding(),
"net.pipe://localhost/StateServer");
}
void context_PreRequestHandlerExecute(object sender, EventArgs e)
{
try
{
if (factory.State != CommunicationState.Opened)
setupFactory();
channel = factory.CreateChannel();
channel.LogAccess("Hello World!");
}
catch (Exception ex)
{
}
finally
{
factory.Close();
}
}
}
}
私の問題は、これが初めて実行されることですが、その後の試みはこのエラーメッセージを引き起こすことです
通信オブジェクト、System.ServiceModel.Channel.ServiceChannelは、障害状態にあるため、通信に使用できません。
私は何か間違ったことをしているように思えます、そして、私は一般的にWCFに初めてのので、これは非常に可能性があります。
この問題は、ChannelFactoryが再現されることを取り巻くことであり、これにより障害状態が発生します。
解決
特定のエラーは、おそらく工場の障害を意味し、例外を投げ(嚥下している)、最終的にブロックが実行されると、工場が障害になっているためにFactory.Close()呼び出しが失敗します(WCFオブジェクトの障害がある場合、必要です。 abort()を呼び出します。
所属していません StackOverflow