WCF + REST: Where is the request data? -
I am currently developing a WCF cool service, within the recognition of POST data, I'm throwing an exception if the request XML does not conform to our business rules.
The goal is to send an e-mail to the appropriate employees, if any request comes in it is considered invalid but, with the incoming request header, method and URI, I also want to send an XML posted.
I can not find a way to access this data. Is WCF really the opportunity to use it before destroying the request body / data or am I forgetting something?
Your help is appreciated because I have an entanglement of why I can not use the request data.
This is not unfortunately supported - we had a common need, and did it by calling internal members With reflection we use it in only one error handler (so we can dump the raw request), but it works fine. I will not recommend it to any system that you do not own and (i.e., do not ship this code to a customer) because it can change the service pack or anything at any time.
Public Stabilized String GetRequestBody () {OperationContact OC = OperationContacts. Present; If (oc == empty) throw a new exception ("no ambient operation contact."); Message Encoder Encoder = o.IncomingMessageProperties.Encoder; String contentType = encoder.contentType; Match match = re-match Match (content type); If (! Match.Success) throw a new exception ("Failed to extract the character set from the requested content type:" + contentType); String charset = match. group 1]. value; Object bufferedMessage = operationContextType.InvokeMember ("Request", BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.GetField, Blank, OC, Blank); // type utility.asserttip (buffermesap type, buffedes); Object messagedata = bufferedMessageType.InvokeMember ("MessageData", BindingFlag.Instance | BindingFlag.NonPolic | BindingFlagGotProperty, Blank, Buffered Message, Blank); // type utility.seertip (jesenbufordmessassadet type, messagedata); Object buffer = jesenbufordmessassettype Invoke member ("buffer", bindingflaag.instance; bindingflag.fbl; bindingflag.getproperty, empty, messaging data, empty); ArraySegment & LT; Byte & gt; Array buffer = (arrecignment & lt; byte & gt;) buffer; Encoding encoding = encoding GetEncoding (characterSet); String request message = encoding.greatstring (arraybuffer array, arraybuffer offset, arborbank.cc); Return request message; }
Comments
Post a Comment