相当于存储在数据库中的 Fiddler SOAP 请求/响应 [英] The equivalent of Fiddler SOAP request/response stored in database
问题描述
我写了很多 WCF 服务给其他服务.我之前在让 Fiddler 记录 SOAP 消息时遇到了麻烦,但现在我可以正常工作了.但是我的老板想要一些完全没有 Fiddler 的东西,我可以将 SOAP 消息传出去,而进来的消息则记录到数据库中.我已经看了很多 WCF 日志记录和诊断并使用数据库源侦听器对其进行了扩展,但是我找不到要使用的数据库源侦听器的实现.
I write a lot of WCF services to other services. I have had trouble with getting Fiddler to log the SOAP messages before but now I have that working. But my boss wants something without Fiddler at all where I can take the SOAP message going out and the one coming in logged to the database. I have looked a lot at WCF Logging and Diagnostics and extending it with Database Source Listener but I cant find an implementation of a Database Source Listener to use.
我认为这甚至不是他想要的.他希望将 Fiddler 的 SOAP 请求/响应显示等价物写入数据库.有人可以帮我吗?
I don't think that's what he even wants. He wants the equivalent of Fiddler's SOAP request/response displays written to the database. Can anyone help me please?
推荐答案
你有两种可能:
编写自定义WCFTrace Listener,调用数据库过程存储日志数据:
Write custom WCF Trace Listener, calling database procedure to store logging data:
public class AsyncMSMQTraceListener : TraceListener
{
public override void TraceData(TraceEventCache eventCache, string source,
TraceEventType eventType, int id, object data)
{
// eventType like for example TraceEventType.Information
var message = data.ToString();
// Here call datbase save log with message
}
public override void Write(string message)
{
}
public override void WriteLine(string message)
{
}
}
但通过这种方式,您将获得跟踪消息,其中请求/响应只是其中的一部分.
but in this way you'll get trace messages, where request/response is only a part of it.
编写自定义消息检查员类:
public class ConsoleOutputMessageInspector : IDispatchMessageInspector
{
public object AfterReceiveRequest(ref Message request, IClientChannel channel, InstanceContext instanceContext)
{
MessageBuffer buffer = request.CreateBufferedCopy(Int32.MaxValue);
request = buffer.CreateMessage();
// Here you can use buffer.CreateMessage().ToString()
return null;
}
public void BeforeSendReply(ref Message reply, object correlationState)
{
MessageBuffer buffer = reply.CreateBufferedCopy(Int32.MaxValue);
reply = buffer.CreateMessage();
// here you can use buffer.CreateMessage().ToString()
}
}
注意:无论您选择哪种方法,我都建议对数据库进行某种异步调用,以免阻塞正常的服务流.
Note: Regardless which method you choose, I would suggest to make some kind of an asynchronous call to the database to not block normal service flow.
这篇关于相当于存储在数据库中的 Fiddler SOAP 请求/响应的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!