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 に答える