开发者

WCF Unique ID for each service method call

开发者 https://www.devze.com 2023-03-29 20:29 出处:网络
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

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.

e.g.

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

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

   var log = LogManager.GetLogger(type);

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

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

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 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.

0

精彩评论

暂无评论...
验证码 换一张
取 消