You are developing a Windows Communication Foundation (WCF) service.
You enable message logging, trace listeners, activity propagation, and tracing on the trace sources.
You have the following code segment in the client application. (Line numbers are included for reference only.)
01 Guid multiCallActivityId = Guid.NewGuid();
02 TraceSource ts = new TraceSource(“Multicall”);
03 Trace.CorrelationManager.ActivityId = multiCallActivityId;
04
You encounter errors when your client application consumes the service.
You need to ensure that your client application can correlate tracing information with the service.
Which code segment should you add at line 04?
A.
ts.TraceEvent(TraceEvencType.Start, 0, “Calling first service”);
ts.TraceTransfer(100, “Transferring…”, multiCallActivityId);
…
ts.TraceEvent(TraceEventType.Stop, 0, “Return from first service.”);
B.
Trace.CorrelationManager.StartLogicalOperation(“1”);
…
Trace.CorrelationManager.StopLogicalOperation();
C.
ts.TraceEvent(TraceEventType.Start, 0, “Calling first service”);
ts.TraceTransfer(100, “Transferring…”, Guid.NewGuid());
…
ts.TraceEvent(TraceEventType.Stop, 0, “Return from first service.”);
D.
ts.TraceEvent(TraceEventType.Start, 0, “Calling first service”);
Trace.CorrelationManager.StartLogicalOperation(“1”);
…
ts.TraceEvent(TraceEventType.Stop, 0, “Return from first service.”);
Explanation:
Propagating the Activity ID to A ServiceWhen the activity ID is propagated across endpoints, the message receiver emits a Start and Stop traces
with that (propagated) activity ID. Therefore, there is a Start and Stop trace with that gAId from each trace source.
If the endpoints are in the same process and use the same trace source name, multiple Start and Stop with
the same lAId (same gAId, same trace source, same process) are created.If you set the propagateActivity attribute to true for the System.ServiceModel trace source in both the client
and service configuration files, the service processing for the Add request occurs in the same activity as the one defined in the client.
If the service defines its own activities and transfers, the service traces do not appear in the client-propagated activity.
Instead, they appear in an activity correlated by transfer traces to the activity whose ID is propagated by the client.Note:
If the propagateActivity attribute is set to true on both the client and service, the ambient activity in the operation scope of the service is set by WCF.
You can use the following code to check whether an activity was set in scope by WCF.// Check if an activity was set in scope by WCF, i.e., if it was
// propagated from the client. If not, i.e., ambient activity is
// equal to Guid.Empty, create a new one.
if(Trace.CorrelationManager.ActivityId == Guid.Empty)
{
Guid newGuid = Guid.NewGuid();
Trace.CorrelationManager.ActivityId = newGuid;
}
// Emit your Start trace.
ts.TraceEvent(TraceEventType.Start, 0, “Add Activity”);// Emit the processing traces for that request.
serviceTs.TraceInformation(“Service receives Add ” + n1 + “, ” + n2);// double result = n1 + n2;
serviceTs.TraceInformation(“Service sends Add result” + result);// Emit the Stop trace and exit the method scope.
ts.TraceEvent(TraceEventType.Stop, 0, “Add Activity”);
// return result;Emitting User-Code Traces
(http://msdn.microsoft.com/en-us/library/aa738759.aspx)Tracing and Message Logging
(http://msdn.microsoft.com/en-us/library/ms751526.aspx)Propagation
(http://msdn.microsoft.com/en-us/library/aa738751.aspx)Service Trace Viewer Tool (SvcTraceViewer.exe)
(http://msdn.microsoft.com/en-us/library/ms732023.aspx)