I've searched a lot for a good answer but got a lot of answers that didn't satisfy me.
We have a service with the usual operations. Inside each operation we call a different project to handle te operation and store some info of the operation inside a database.
We've got a new requirement: Store the soap message of the operation in the database too. Is it possible to receive the soap (xml) from the wcf operation? Or are event really needed?
I was unable to use OperationContext.Current.RequestContext.RequestMessage.ToString()
because it translates the request into Xml. When the request is JSON, I'd prefer it stay that way. I also found that, by the time an endpoint's method is invoked, Request.InputStream
is empty---even when I have <add key="wcf:serviceHostingEnvironment:useClassicReadEntityBodyMode" value="true" />
in web.config (FYI: the app is running .Net 4.5.2).
So, what I did was to implement Application_BeginRequest
in Global.asax.cs. I extract the contents of Request.InputStream
there, and save that request body to Context.Items
. Later, in IErrorHandler
's ProvideFault(...)
, I transfer the saved string over to the Exception's Data
property so that the logging will later capture it when HandleError(...)
runs (Items
is empty by the time HandleError
runs).
For myself i found this solution to get the raw soap message in framework 4.5:
OperationContext.Current.RequestContext.RequestMessage.ToString()
Read all comments above for more details about alternatives and their problems.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With