WCF REST. Is it possible to log the requests that were received from the client to the Database?
I am new to WCF. I have a WCF REST service that implments the ServiceAuthorizationManager. The requirement is to log the request received from the clients to a table in the DB. Where should this happen, I mean in the AuthorizationManager that implements ServiceAuthorizationManager? and how to gather all the info like the IP Address of the client, the auth headers passed by the client so that I can populate an object and make a db call in the Application_开发者_如何学编程EndRequest of Global.asax class.
Please advise.
Thanks, Raju
Consider adding a message inspector to your service. I found this link that might be helpful: WCF REST Message Inspector
In the AfterReceiveRequest
method you can extract header information etc. from the request header.
Implement your logic in BeforeSendReply
instead of in Application_EndRequest
.
If you're hosting your service in IIS 7+, an easier way would be to setup AppFabric and enable end-to-end monitoring for that service rather than rolling your own. Here's a blog post that shows a sample service and the config required to get this working.
If you decide to go the ServiceAuthorizationManager route, check out this MSDN article on using that class. It shows how to override the CheckAccessCore method and retrieve the message headers, etc. This is where you could implement the call to log the request if authorization succeeds.
精彩评论