1

我的 wcf 服务托管在 iis7 中。有没有办法我可以在 ApplyDispatchBehavior 方法中设置断点,并确保在运行时通过击中该断点来调用它?我的总体问题是在 CultureMessageInspector 类中没有命中方法 AfterReceiveRequest。我的代码的详细信息已发布在以下链接中的问题下。请帮助我..谢谢

wcf AfterReceiveRequest 没有被调用

在 iis 托管的 wcf 服务中传递文化值

public class CultureBehaviour : IEndpointBehavior
    {
        #region IEndpointBehavior Members

        public void AddBindingParameters(ServiceEndpoint endpoint, System.ServiceModel.Channels.BindingParameterCollection bindingParameters)
        {
        }

        public void ApplyClientBehavior(ServiceEndpoint endpoint, System.ServiceModel.Dispatcher.ClientRuntime clientRuntime)
        {
            CultureMessageInspector inspector = new CultureMessageInspector();
            clientRuntime.MessageInspectors.Add(inspector);
        }

        public void ApplyDispatchBehavior(ServiceEndpoint endpoint, System.ServiceModel.Dispatcher.EndpointDispatcher endpointDispatcher)
        {
            CultureMessageInspector inspector = new CultureMessageInspector();
            endpointDispatcher.DispatchRuntime.MessageInspectors.Add(inspector);
        }

        public void Validate(ServiceEndpoint endpoint)
        {
        }

        #endregion
    }

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
    }
4

1 回答 1

1

假设 PDB 文件存在于您的 bin 目录中,您可以简单地将调试器附加到 IIS7 进程并正常调试。

确保 web.config 设置了 debug="true"。

有关更多详细信息,请参阅此答案

将调试器附加到 IIS 实例

于 2012-08-17T19:54:17.097 回答