0

When I host my wcf service via webiste iis7, the method AfterReceiveRequest does not get called.

Please help..

Thanks

public class CultureMessageInspector : IClientMessageInspector, IDispatchMessageInspector
{
    private const string HeaderKey = "culture";
    #region IDispatchMessageInspector Members

    public object AfterReceiveRequest(ref System.ServiceModel.Channels.Message request, System.ServiceModel.IClientChannel channel, System.ServiceModel.InstanceContext instanceContext)
    {
        int headerIndex = request.Headers.FindHeader(HeaderKey, string.Empty);
        if (headerIndex != -1)
        {
            Thread.CurrentThread.CurrentCulture = new CultureInfo(request.Headers.GetHeader<String>(headerIndex));
        }
        return null;
    }

    public void BeforeSendReply(ref System.ServiceModel.Channels.Message reply, object correlationState)
    {
    }

    #endregion

    #region IClientMessageInspector Members

    public void AfterReceiveReply(ref System.ServiceModel.Channels.Message reply, object correlationState)
    {
    }

    public object BeforeSendRequest(ref System.ServiceModel.Channels.Message request, System.ServiceModel.IClientChannel channel)
    {
        request.Headers.Add(MessageHeader.CreateHeader(HeaderKey, string.Empty, Thread.CurrentThread.CurrentCulture.Name));
        return null;
    }

    #endregion
}

My Behavior Extension class, Service.svc, and config settings are as follows:

<system.serviceModel>
    <services>
      <service name="C:\Visual Studio 2010\WebSites\WCFService8">
        <endpoint binding="netTcpBinding" bindingConfiguration="" behaviorConfiguration="Default" contract="CultureServer.IHelloWorld" />
      </service>
    </services>
    <behaviors>

      <endpointBehaviors>
        <behavior name="Default">
          <CultureExtension/>
        </behavior>
      </endpointBehaviors>

      <serviceBehaviors>
        <behavior>
          <!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->
          <serviceMetadata httpGetEnabled="true"/>
          <!-- To receive exception details in faults for debugging purposes, set the value below to true.  Set to false before deployment to avoid disclosing exception information -->
          <serviceDebug includeExceptionDetailInFaults="false"/>
        </behavior>
      </serviceBehaviors>
    </behaviors>

    <extensions>
      <behaviorExtensions>
        <add name="CultureExtension" type="Extension.CultureBehaviorExtension, Extension, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"/>
      </behaviorExtensions>
    </extensions>

    <serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
  </system.serviceModel>


public class CultureBehaviorExtension : BehaviorExtensionElement
{
    // BehaviorExtensionElement members
    public override Type BehaviorType
    {
        get { return typeof(CultureBehaviour); }
    }

    protected override object CreateBehavior()
    {
        return new CultureBehaviour();
    }
}


<%@ ServiceHost Language="C#" Debug="true" Service="CultureServer.Server"%>
dotnet-practitioner
  • 13,968
  • 36
  • 127
  • 200

1 Answers1

1
<services> 
  <service name="C:\Visual Studio 2010\WebSites\WCFService8"> 
    <endpoint binding="netTcpBinding" bindingConfiguration="" behaviorConfiguration="Default" contract="CultureServer.IHelloWorld" /> 
  </service> 
</services> 

The name attribute for the <service> tag is wrong. It should have the class name, not a path. Try replacing it with the code below.

<services> 
  <service name="CultureServer.Server"> 
    <endpoint binding="netTcpBinding" bindingConfiguration="" behaviorConfiguration="Default" contract="CultureServer.IHelloWorld" /> 
  </service> 
</services> 
carlosfigueira
  • 85,035
  • 14
  • 131
  • 171
  • Hi Carlos I have been watching your wcf tutorials on PluralSight. They are great. But so far I could not get this to work. I will try this approach right now and see if this works. Thanks – dotnet-practitioner Aug 17 '12 at 16:18
  • Carlos, if I replace the name attribute with classname and take out the path, I get error when I browse the .svc file locally on my VS. – dotnet-practitioner Aug 17 '12 at 16:31
  • Carlos, here is the error: Could not find a base address that matches scheme net.tcp for the endpoint with binding NetTcpBinding. Registered base address schemes are [http]. – dotnet-practitioner Aug 17 '12 at 19:29
  • Also, since I am hosting the service in IIS7, I don't think that ApplyDispatchBehavior method is being invoked in my behavior class. – dotnet-practitioner Aug 17 '12 at 19:30
  • more details of my code are in this link : http://stackoverflow.com/questions/11994697/passing-culture-value-inside-wcf-service-hosted-by-iis – dotnet-practitioner Aug 17 '12 at 19:31
  • If you want to host a WCF service using TCP on IIS, you must enable that binding (which by default isn't) on IIS manager. Also, on the application / vdir, you need to add "net.tcp" as one of the supported protocols. – carlosfigueira Aug 17 '12 at 23:21
  • Carlos, your recommendations have already been implemented because I watched your videos. I got it to work now simply by attaching to iis wp process and stepping through the code. After that step through, some how, things auto-magically work. Thanks – dotnet-practitioner Aug 17 '12 at 23:36