Search code examples
wcfruntime-errortrace

WCF - Tracking Logging - ActivityId being added to soap header causing error


Overview of the error: We turned on Wcf trace logging to find a random disconnect error from a 3rd party Web Service. When the Wcf trace logging is on, only one of the two 3rd party service calls error out because of the <ActivityId..../> which is added to the <s:Header>. The error we receive is below:

The soap request showing the addition of the <ActivityId.....> added to the <s:Header> which is not there when the Wcf tracing is not on.

<ApplicationData>
    <TraceData>
        <DataItem>
            <MessageLogTraceRecord Time="2022-09-02T15:03:48.1440318-05:00" Source="TransportSend" Type="System.ServiceModel.Dispatcher.OperationFormatter+OperationFormatterMessage" xmlns="http://schemas.microsoft.com/2004/06/ServiceModel/Management/MessageTrace">
                <Addressing>
                    <Action>urn:ApiControllerw#BList</Action>
                    <To>https://www.example.net/api/index.html?ws=1</To>
                </Addressing>
                <s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
                    <s:Header>
                        <ActivityId CorrelationId="80f89d90-5b02-47ef-8d43-1cd729d1dd69" xmlns="http://schemas.microsoft.com/2004/09/ServiceModel/Diagnostics">00000000-0000-0000-0000-000000000000</ActivityId>
                    </s:Header>
                    <s:Body xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
                        <BList xmlns="urn:ApiControllerw"></BList>
                    </s:Body>
                </s:Envelope>
            </MessageLogTraceRecord>
        </DataItem>
    </TraceData>
</ApplicationData>

Once Wcf tracing is turned on, we start receiving an error when a call to one of the soap services is hit. The error relates to not knowing how to deal with the ActivityID. The error is below:

<ApplicationData>
    <TraceData>
        <DataItem>
            <MessageLogTraceRecord Time="2022-09-02T15:03:48.3750527-05:00" Source="TransportSend" Type="System.ServiceModel.Channels.BodyWriterMessage"
                xmlns="http://schemas.microsoft.com/2004/06/ServiceModel/Management/MessageTrace">
                <Addressing>
                    <Action>http://schemas.microsoft.com/net/2005/12/windowscommunicationfoundation/dispatcher/fault</Action>
                </Addressing>
                <s:Envelope
                    xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
                    <s:Body>
                        <s:Fault>
                            <faultcode
                                xmlns:a="http://schemas.microsoft.com/net/2005/12/windowscommunicationfoundation/dispatcher"
                                xmlns="">a:InternalServiceFault
                            </faultcode>
                            <faultstring xml:lang="en-US"
                                xmlns="">Call to company BList operation failed.
                            </faultstring>
                            <detail
                                xmlns="">
                                <ExceptionDetail
                                    xmlns="http://schemas.datacontract.org/2004/07/System.ServiceModel"
                                    xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
                                    <HelpLink i:nil="true"></HelpLink>
                                    <InnerException>
                                        <HelpLink i:nil="true"></HelpLink>
                                        <InnerException i:nil="true"></InnerException>
                                        <Message>ApiController and its behaviors do not have a method or closure named "ActivityId".</Message>
                                        <StackTrace>
Server stack trace: at System.ServiceModel.Channels.ServiceChannel.HandleReply(ProxyOperationRuntime operation, ProxyRpc&rpc)at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[]ins, Object[]outs, TimeSpan timeout)at System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage methodCall, ProxyOperationRuntime operation)at System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage message)Exception rethrown at [0]: at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData&msgData, Int32 type)at ServiceLibrary.CompanyService.ApiControllerPortType.BList(BListRequest request)at ServiceLibrary.CompanyService.ApiControllerPortTypeClient.ServiceLibrary.CompanyService.ApiControllerPortType.BList(BListRequest request) in C:\TeamCity\buildAgent2\work\TankMonitorServiceLibrary\Service References\CompanyService\Reference.cs:line 3758at ServiceLibrary.CompanyService.ApiControllerPortTypeClient.BList() in C:\TeamCity\buildAgent2\work\ServiceLibrary\Service References\CompanyService\Reference.cs:line 3763at ServiceLibrary.Service.GetBList() in C:\TeamCity\buildAgent2\work\ServiceLibrary\Service.cs:line 311
</StackTrace>
                                        <Type>System.ServiceModel.FaultException</Type>
                                    </InnerException>
                                    <Message>Call to Company BList operation failed.</Message>
                                    <StackTrace>
at ServiceLibrary.Service.GBList() in C:\TeamCity\buildAgent2\work\ServiceLibrary\Service.cs:line 317at SyncInvokeGetBranchList(Object , Object[], Object[])at System.ServiceModel.Dispatcher.SyncMethodInvoker.Invoke(Object instance, Object[]inputs, Object[]&outputs)at System.ServiceModel.Dispatcher.DispatchOperationRuntime.InvokeBegin(MessageRpc&rpc)at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage5(MessageRpc&rpc)at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage11(MessageRpc&rpc)at System.ServiceModel.Dispatcher.MessageRpc.Process(Boolean isOperationContextSet)
</StackTrace>
                                    <Type>System.ServiceModel.CommunicationException</Type>
                                </ExceptionDetail>
                            </detail>
                        </s:Fault>
                    </s:Body>
                </s:Envelope>
            </MessageLogTraceRecord>
        </DataItem>
    </TraceData>
</ApplicationData>

Solution

  • Your answer can be found at https://stackoverflow.com/a/28235151

    • Remove ActivityTracing from switchvalue
    • Set propagateActivity to false

    See https://learn.microsoft.com/en-us/dotnet/framework/wcf/diagnostics/tracing/activity-id-propagation for more info.