简体   繁体   中英

put a breakpoint at ApplyDispatchBehavior method while wcf service hosted in iis7

My wcf service is being hosted in iis7. Is there a way I could put break point at ApplyDispatchBehavior method and make sure that its being called at run time by hitting that breakpoint?? My overall problem is that method AfterReceiveRequest is not being hit in the CultureMessageInspector class. Details of my code have been posted under questions in the following links. Please help me.. thanks

wcf AfterReceiveRequest not getting called

passing culture value inside wcf service hosted by iis

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
    }

Presuming that the PDB files are present in your bin directory you can simply attach a debugger to the IIS7 process and debug as normal.

Make sure that the web.config has debug="true" set.

See this answer for more details

Attach Debugger to IIS instance

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM