Mel*_*per 5 .net c# asp.net wcf asp.net-core
我们曾经使用过ASP.NET上的WCF,最近又切换到了ASP.NET Core上的WCF。这很难实现,因为ASP.Net Core不支持WCF。一方面,整个web.config XML配置模型已转储到ASP.NET Core中,因此我们无法在此处配置WCF跟踪。
即该文档无用:https : //docs.microsoft.com/zh-cn/dotnet/framework/wcf/diagnostics/tracing/configuring-tracing
我们必须通过在WCF和端口80之间放置一个http代理来入侵ASP.NETCore。WCF实际上在另一个端口上运行。
问题是,如果ASP.NET Core不关注web.config,如何启用WCF跟踪?
Pet*_*kiy 12
在客户端跟踪的情况下,我使用自定义端点行为 ( IEndpointBehavior) 和自定义消息日志检查器 ( IClientMessageInspector) 来获取输入和输出消息。
客户端初始化:
_serviceClient = new MyCustomServiceClient();
_serviceClient.Endpoint.Address = new System.ServiceModel.EndpointAddress(_configParams.ServiceUri);
_serviceClient.Endpoint.EndpointBehaviors.Add(new EndpointLoggingBehavior("MyCustomService"));
Run Code Online (Sandbox Code Playgroud)
实施EndpointLoggingBehavior:
public class EndpointLoggingBehavior : IEndpointBehavior
{
public EndpointLoggingBehavior(string serviceName)
{
_serviceName = serviceName;
}
private readonly string _serviceName;
public void AddBindingParameters(ServiceEndpoint endpoint,
System.ServiceModel.Channels.BindingParameterCollection bindingParameters)
{
}
public void ApplyClientBehavior(ServiceEndpoint endpoint, ClientRuntime clientRuntime)
{
clientRuntime.ClientMessageInspectors.Add(new MessageLoggingInspector(_serviceName));
}
public void ApplyDispatchBehavior(ServiceEndpoint endpoint, EndpointDispatcher endpointDispatcher)
{
}
public void Validate(ServiceEndpoint endpoint)
{
}
}
Run Code Online (Sandbox Code Playgroud)
实施MessageLoggingInspector:
public class MessageLoggingInspector : IClientMessageInspector
{
private readonly string _serviceName;
public MessageLoggingInspector(string serviceName)
{
_serviceName = serviceName;
}
public void AfterReceiveReply(ref Message reply, object correlationState)
{
// copying message to buffer to avoid accidental corruption
var buffer = reply.CreateBufferedCopy(int.MaxValue);
reply = buffer.CreateMessage();
// creating copy
var copy = buffer.CreateMessage();
//getting full input message
var fullInputMessage = copy.ToString();
}
public object BeforeSendRequest(ref Message request, IClientChannel channel)
{
// copying message to buffer to avoid accidental corruption
var buffer = request.CreateBufferedCopy(int.MaxValue);
request = buffer.CreateMessage();
// creating copy
var copy = buffer.CreateMessage();
//getting full output message
var fullOutputMessage = copy.ToString();
return null;
}
}
Run Code Online (Sandbox Code Playgroud)
然后,当然,您需要将这些消息写入任何存储。
小智 2
您将在 .NET Core 上使用 ETW 跟踪 WCF
https://github.com/dotnet/wcf/blob/master/Documentation/HowToUseETW.md
根据我的经验,你有一些限制
ETW 的好处
| 归档时间: |
|
| 查看次数: |
668 次 |
| 最近记录: |