WCF Service programming-message tracking for WCF applications

Source: Internet
Author: User

Message tracing for WCF mainly includes Microsoft Service Trace Viewer and tcpTrace. The Service Tracking Viewer tool has powerful functions to understand the diagnostic tracing information generated by the WCF listener, so as to find the root cause of the error. This tool provides an easy way to view, group, and filter traces, so that you can diagnose, fix, and verify issues with the WCF Service. However, you need to configure it on the server before using it. TcpTrace is actually a tool that uses port ing to capture Tcp packets. It is very easy to use because many of the WCF bindings use the tcp protocol. The following describes how to use these two tools.

 

Microsoft Service Trace Viewer

Service Trace Viewer is a self-returning tool of. Net Framework. It can be found in the C: \ Program Files \ Microsoft SDKs \ Windows \ v6.0A \ Bin path. Taking the source code in "WCF Service programming-HelloWorld" as an example, we need to change the server's App. Config configuration file before using it:

Diagnostics Configure
<? Xml version = "1.0" encoding = "UTF-8"?>
<Configuration>
<! -- WCF configuration declaration -->
<System. serviceModel>
<! -- Add a trail node -->
<Diagnostics performanceCounters = "All" wmiroviderenabled = "true">
<MessageLogging logEntireMessage = "true" logMalformedMessages = "true" logMessagesAtServiceLevel = "true" logMessagesAtTransportLevel = "true" maxMessagesToLog = "100000"/>
</Diagnostics>
<Services>
<Endpoint address = "" binding = "basicHttpBinding" contract = "Cbcye. Contract. IHelloWorld" name = ""> </endpoint>
<Host>
<BaseAddresses>
<Add baseAddress = "http: // localhost: 7788/cbcye/helloworld % 22/>
</BaseAddresses>
</Host>
</Service>
</Services>

<! -- Tracking node configuration -->
<System. diagnostics>
<SharedListeners>
<Add name = "sharedListener"
Type = "System. Diagnostics. XmlWriterTraceListener"
InitializeData = "c: \ temp \ trace. svclog"/>
</SharedListeners>
<Sources>
<Source name = "System. ServiceModel" switchValue = "Verbose, ActivityTracing">
<Listeners>
<Add name = "sharedListener"/>
</Listeners>
</Source>
<Source name = "System. ServiceModel. MessageLogging" switchValue = "Verbose">
<Listeners>
<Add name = "sharedListener"/>
</Listeners>
</Source>
</Sources>
</System. diagnostics>

</Configuration>

Run the WCF server and client to generate communication data between the WCF server and the client.

Open the service tracking viewer and open the file corresponding to the initializeData attribute path in the configuration file. Then we can view the corresponding data in the viewer.

 

TcpTrace

TcpTrace is easy to use. When tcpTrace is started, the port to be mapped is entered. For example, in "WCF Service programming-HelloWorld", before using it, we need to change the port number of the client request address from 7788 to 8080, in this way, the client sends the data to the tcpTrace listening port 8080 when requesting the service, and the tcpTrace forwards the data to the service at Port 7788.

The WCF data that tcpTrace listens to (Note: tcpTrace only supports messages transmitted over tcp)

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.