Reputation: 444
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?
Upvotes: 8
Views: 6206
Reputation: 4379
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).
Upvotes: 5
Reputation: 444
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.
Upvotes: 4