15 days proficient in WCF-11th days how to monitor the entire process of wcf

Source: Internet
Author: User

15 days proficient in WCF-11th days how to monitor the entire process of wcf

When we are playing asp.net, we all know that there is a hairy thing called "lifecycle". We can use httpmodule in the page_load before the page.

There are many benefits for blocking, such as logging, parameter filtering, and global login verification... Similar functions are provided in wcf. The first one is

Add the runtime behavior to the endpoint, so that we can intercept it before the "service method". The second method is the full-process monitoring that we refer to in this article.

"Diagnostic function ".

 

I. Diagnosis

I also said, "diagnosis" is a specialized term in wcf, which means to monitor all the movements of wcf. If so, it can be divided into message monitoring and wcf

Service status information and end-to-end flow messages.

1. Transfer Messages from end to end

Before playing with wcf, I don't know how many people are familiar with Diagnostics. Right, it is the log class that comes with. net. Of course, there are many log recording components in this age, such

Log4net, Nlog, etc... However, Diagnostics is still an alternative method. It consists of a "tracking source" and a "listener. TraceSource

To specify the tracing source and use TraceListener to specify the tracing source listener. Therefore, all traces of TraceSource will be monitored by TraceListener.

See how to play.

<?xml version="1.0" encoding="utf-8"?><configuration>  <system.diagnostics>    <sources>      <source name="System.ServiceModel" switchValue="ActivityTracing">        <listeners>          <add name="mylisteners" type="System.Diagnostics.XmlWriterTraceListener" initializeData="E:\1.txt" />        </listeners>      </source>    </sources>    <trace autoflush="true"/>  </system.diagnostics>  <system.serviceModel>    <behaviors>      <serviceBehaviors>        <behavior>          <serviceMetadata httpGetEnabled="true" />          <serviceDebug includeExceptionDetailInFaults="false" />        </behavior>      </serviceBehaviors>    </behaviors>    <services>      <service name="MyService.HomeService">        <endpoint address="HomeService" binding="wsHttpBinding"          contract="MyService.IHomeService">          <identity>            <dns value="localhost" />          </identity>        </endpoint>        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />        

From the configuration above, can you see that I have nothing to do with wcf When configuring system. diagnostics?

There is a little bit of configuration for diagnostics, right? What does this mean? The trace function has nothing to do with wcf, but it can completely record the tracing information of wcf. However

Then I will explain a little bit about the listeners node. Here I configure an XmlWriterTraceListener listener and configure the output file path under the initializeData attribute,

Actually, they all belong to the scope of diagnostics, and they have nothing to do with wcf. Well, let's start the program and see what is tracked in the end?

Have you seen that when my service is started, all the tracing information comes... But the next question is, how can we see this messy xml to be the most comfortable?

What about ??? You don't have to worry about it. wcf also provides us with a tool called SvcTraceView, specifically used to find this "trace information". The tool path is as follows:

C: \ Program Files (x86) \ Microsoft SDKs \ Windows \ v8.0A \ bin \ NETFX 4.0 Tools

 

In the following example, open the 1.txt file, as shown in the following figure:

From the "activity diagram" on the left, we can see what kind of miserable stories HomeService has experienced since it started to run... If you are interested, you can do it yourself.

Try it.

 

2. Monitor the message of input and ouput

To monitor the message, we need to define another TraceSource and TraceListener, but this time the System. ServiceModel.

MessageLogging traces the source, and then configure the message parameters under System. ServiceModel, as follows:

 1 <?xml version="1.0" encoding="utf-8"?> 2 <configuration> 3  4   <system.diagnostics> 5     <sources> 6       <source name="System.ServiceModel" switchValue="ActivityTracing"> 7         <listeners> 8           <add name="mylisteners" type="System.Diagnostics.XmlWriterTraceListener" initializeData="E:\1.txt" /> 9         </listeners>10       </source>11       <source name="System.ServiceModel.MessageLogging" switchValue="ActivityTracing">12         <listeners>13           <add name="messagelogging" type="System.Diagnostics.XmlWriterTraceListener" initializeData="E:\2.txt"/>14         </listeners>15       </source>16     </sources>17     <trace autoflush="true"/>18   </system.diagnostics>19 20   <system.serviceModel>21 22     <diagnostics>23       <messageLogging logEntireMessage="true" logMalformedMessages="true"  logMessagesAtTransportLevel="true" />24     </diagnostics>25 26     <behaviors>27       <serviceBehaviors>28         <behavior>29           <serviceMetadata httpGetEnabled="true" />30           <serviceDebug includeExceptionDetailInFaults="false" />31         </behavior>32       </serviceBehaviors>33     </behaviors>34 35     <services>36       <service name="MyService.HomeService">37         <endpoint address="HomeService" binding="basicHttpBinding"38           contract="MyService.IHomeService">39           <identity>40             <dns value="localhost" />41           </identity>42         </endpoint>43         <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />44         

 

This time I am going to run the client and call the Update method on the Server to see what Messsage can be captured.

 

 

Now I want to use svctraceviewto open 2.txt and see what tracing information is available...

 

 

Okay, I will introduce SvcTraceView in a simple way. For more details about the gameplay, you can think about it. By the way, if you want

For more information about some parameters, see SvcConfigEditor. For example, you can see the following...

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.