0

当我通过webiste iis7托管我的 wcf 服务时,没有调用AfterReceiveRequest方法

请帮忙..

谢谢

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
}

我的行为扩展类、Service.svc 和配置设置如下:

<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"%>
4

1 回答 1

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

标签的name属性错误。<service>它应该有类名,而不是路径。尝试用下面的代码替换它。

<services> 
  <service name="CultureServer.Server"> 
    <endpoint binding="netTcpBinding" bindingConfiguration="" behaviorConfiguration="Default" contract="CultureServer.IHelloWorld" /> 
  </service> 
</services> 
于 2012-08-17T03:26:38.620 回答