zoukankan      html  css  js  c++  java
  • 自定义的一个Behavior: 从Debug输出看到来回的Messages

    就两个class, 好用又方便~

    MyMessageInspector

    using System;

    using System.Xml;

    using System.IO;

    using System.ServiceModel;

    using System.ServiceModel.Channels;

    using System.ServiceModel.Dispatcher;

     

    namespace WCFExtentions

    {

        public class MyMessageInspector : IDispatchMessageInspector

        {

            public object AfterReceiveRequest(ref Message request, IClientChannel channel, InstanceContext instanceContext)

            {

                System.Diagnostics.Debug.WriteLine(request.ToString());

                return null;

            }

     

            public void BeforeSendReply(ref Message reply, object correlationState)

            {

                System.Diagnostics.Debug.WriteLine(reply.ToString());

            }

        }

    }


    MyMessageInspectionBehaviorAttribute

    using System;

    using System.ServiceModel;

    using System.Collections.ObjectModel;

    using System.ServiceModel.Channels;

    using System.ServiceModel.Description;

    using System.ServiceModel.Dispatcher;

     

    namespace WCFExtentions

    {

        [AttributeUsage(AttributeTargets.Class)]

        public class MyMessageInspectionBehaviorAttribute : Attribute, IServiceBehavior  

        {

            #region IServiceBehavior Members

     

            public void AddBindingParameters(ServiceDescription serviceDescription, ServiceHostBase serviceHostBase, Collection<ServiceEndpoint> endpoints, BindingParameterCollection bindingParameters)

            {     

            }

     

            public void ApplyDispatchBehavior(ServiceDescription serviceDescription, ServiceHostBase serviceHostBase)

            {

                foreach (ChannelDispatcher channelDispatch in serviceHostBase.ChannelDispatchers)

                {

                    foreach (EndpointDispatcher endpointDispatch in channelDispatch.Endpoints)

                    {

                        endpointDispatch.DispatchRuntime.MessageInspectors.Add(new MyMessageInspector());

                    }

                }

            }

     

            public void Validate(ServiceDescription serviceDescription, ServiceHostBase serviceHostBase)

            {

            }

     

            #endregion

        }

    }


    给服务的加上这个属性, 然后你就可以在调试的时候看到了:
     

    原文地址: http://blogs.msdn.com/kaevans/archive/2006/10/01/779886.aspx

  • 相关阅读:
    robotframework
    robotframework
    robotframework
    robotframework
    Moco模拟服务器post&get请求 (二)
    CentOS7使用——xShell远程连接终端中文乱码
    CentOS7使用——系统安装jdk
    Linux命令——CentOS7防火墙使用
    配置Jenkins 实现自动发布maven项目至weblogic(svn+maven+weblogic12c)
    Windows下配置Jenkins 实现自动发布maven项目至tomcat(svn+maven+tomcat)
  • 原文地址:https://www.cnblogs.com/Dah/p/520052.html
Copyright © 2011-2022 走看看