Note that there are some explanatory texts on larger screens.

plurals
  1. POUtilizing a WCF channel from an IIS ASP.net IHttpModule
    text
    copied!<p>I have an ASP.net project which involves using a custom IHttpModule. This module will sit in the pipeline and when certain criteria match up, it should invoke a method on a WCF service hosted in a simple C# console application on the same machine.</p> <p>The code for the module is below:</p> <pre><code>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&lt;IStateServer&gt; 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&lt;IStateServer&gt;( 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(); } } } } </code></pre> <p>My problem is that this runs the first time, but then subsequent attempts cause this error message</p> <blockquote> <p>The communication object, System.ServiceModel.Channels.ServiceChannel, cannot be used for communication because it is in the Faulted state.</p> </blockquote> <p>It seems as if I am doing something wrong, and I am new to WCF in general so this is very likely.</p> <p>I think the issue is surrounding the ChannelFactory being recreated, and this causes the faulted state.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload