每个服务方法调用的 WCF 唯一 ID [英] WCF Unique ID for each service method call

查看:35
本文介绍了每个服务方法调用的 WCF 唯一 ID的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 log4net 进行日志记录,并且我想记录每个服务方法调用的唯一 ID.我不需要它在服务调用中是唯一的,只是在方法调用中.我可以在 wcf 中使用任何内置 id 吗?我不想在方法调用开始时手动创建 guid 或其他东西.

I'm logging using log4net, and I want to log a id that is unique for each serice method call. I dont need it unique across service calls, just within a method call. Is there any built in id i can use in wcf? I don't want to manually create a guid or something at the start of the method call.

例如

wcfMethod(int x)
{
 log("xxx");
 somework
 log("yyy");
}

private log(string message)
{
   var frame = new StackFrame(1);
   var method = frame.GetMethod();
   var type = method.DeclaringType;
   var name = method.Name;

   var log = LogManager.GetLogger(type);

   // LOG ID HERE
   ThreadContext.Properties["MessageId"] =    OperationContext.Current.IncomingMessageHeaders.MessageId; // SOMETHING HERE
}

我试过 OperationContext.Current.IncomingMessageHeaders.MessageId 但那总是空的.

I've tried OperationContext.Current.IncomingMessageHeaders.MessageId but thats always null.

我已经阅读了 wcf 实例关联,但我不需要那么复杂的东西(例如,在不同的方法调用中是唯一的).

I've read about wcf instance correlation but i don't need something that complicated (e.g. unique across different method calls).

请如果有人可以提供帮助,那将非常感激.提前致谢.

Please if anyone can help that would be much apprieciated. Thanks in advance.

推荐答案

Plain SOAP 或 REST 在消息中不包含此类标识.您必须使用一些支持消息标识的附加功能或传输协议(例如 MSMQ).在 MessageId 的情况下,您必须使用带有 WS-Addressing 的 SOAP 服务,并且此信息必须从客户端传递.

Plain SOAP or REST has no such identification included in messages. You must use some additional feature or transport protocol (for example MSMQ) supporting identifications of messages. In case of MessageId you have to use SOAP service with WS-Addressing and this information must be passed from client.

这篇关于每个服务方法调用的 WCF 唯一 ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆