问题
I have the following problem. I'm connecting to a Java SOAP service using WCF. On the java logs there seems to be a problem where the last user credentials are being sent instead of the current one, although just for the first call that the user makes.
The problem is that I don't control the Java side and I don't know if the problem is with them as I can't find a place in my code where I think this may be happening. I want to confirm that the username that we are sending is the same one that they have in their logs. This is hard to test also because it only happens in our test environment with multiple user at the same time and I can't reproduce it on local.
However, when I try to trace the WCF call I get a "Removed!" text where the user name should be. I understand this being done for the password, but I really need to see the username that it is being sent.
Is there a way somewhere on the trace options to remove this? Currently I'm using this:
<system.diagnostics>
<sources>
<source name="System.ServiceModel.MessageLogging">
<listeners>
<add name="messages"
type="System.Diagnostics.TextWriterTraceListener"
initializeData="c:\logs\messages5.svclog" />
</listeners>
</source>
</sources>
</system.diagnostics>
and inside system.serviceModel
<diagnostics>
<messageLogging logEntireMessage="true"
logMalformedMessages="true"
logMessagesAtServiceLevel="true"
logMessagesAtTransportLevel="true"
maxMessagesToLog="300000" />
</diagnostics>
回答1:
By default inside the Microsoft Service Trace Viewer application when viewing a WCF Trace, the username and Password field(s) are shown as "". I got around this issue by following this article:
https://msdn.microsoft.com/en-us/library/ms730318.aspx
In your machine.config depends on (.NET version e.g. 2.0, 3.0 etc and bitage e.g. x86, x64) you have to enable
<configuration>
<system.serviceModel>
<machineSettings enableLoggingKnownPii="true"/>
</system.serviceModel>
</configuration>
Then in your web.config in your application enable
<system.diagnostics>
<sources>
<source name="System.ServiceModel.MessageLogging"
logKnownPii="true">
<listeners>
<add name="messages"
type="System.Diagnostics.XmlWriterTraceListener"
initializeData="c:\logs\messages.svclog" />
</listeners>
</source>
</sources>
</system.diagnostics>
with an extra requirement for .net 4.5
In .NET Framework 4.5 the logEntireMessage
and logKnownPii
flags must also be set to true in the Web.config file or the App.config file to enable PII logging, as show in the following example
来源:https://stackoverflow.com/questions/33875371/how-to-see-the-username-on-a-wcf-call-trace