If you want to view the messages and parameters being sent to and from your Wcf Services you can follow these simple steps.
To demonstrate we will be creating a new “WCF Service Library” project:
Right click on your App.Config file and select “Edit Wcf Configuration”.
Select the Diagnostics node (on the left hand side of the form), and then click “Enable Message Logging” (on the right hand side of the form).
Next click the setting for Log Level (set to “Malformed, Transport” by default and select “Service Messages” as shown below:
Finally, expand the Diagnostics node and select the Message Logging node and change the LogEntireMessage setting to True.
Close the Microsoft Service Configuration Editor, saving your changes.
By default the Editor sets the log file to an absolute file path. You can change this in the App.Config to a relative path:
From:
To:
Press F5 to run your WCF Service Library, double click on the GetData() method within the IService1 contract. Enter a request value for the operation on the right hand side, we’ll be using 1234 for this example, and click “Invoke”.
Now close your WCF Test Client window.
To view your Service Log file, open Windows Explorer and navigate to your Project output folder. For this example that directory is C:\Projects\WcfTracingDemo\WcfTracingDemo\Bin\Debug.
You will now be able to see your new log file: app_messages.svclog
Double click on the file to open it within the Microsoft Service Trace Viewer application and select the activity line on the left hand side.
This will populate the Message Log Trace lines on the right hand side, to see your request scroll down to the second to last entry and select it. To view the request scroll down on the “Formatted” tab to view the formatted request:
To view the response select the last entry in the Message Log Trace lines and again scroll down within the “Formatted” section to reveal your response.
I hope you find this brief tutorial on how to Trace messages in WCF comes in useful – happy coding!
Source code: WcfTracingDemo.zip
No comments:
Post a Comment