カスタム 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.Channels.ServiceChannel は、Faulted 状態であるため、通信に使用できません。
私は何か間違ったことをしているように見えます.WCF全般に慣れていないので、これは非常に可能性が高いです.
ChannelFactory が再作成されていることに問題があると思います。これにより、障害状態が発生します。