Note that there are some explanatory texts on larger screens.

plurals
  1. POExtract SOAP Method from HttpRequest object in C#
    primarykey
    data
    text
    <p>I have a logging method that gets called every time a WebService is called and is used to log information about the call. I need to be able to extract the Service Method name that was called for logging purposes. </p> <p>How can I do this with just the HttpRequest object passed into the logging function?</p> <pre><code> public static void LogApiCall(HttpRequest httpRequest, string resultText = "Success", int resultCode = 0) { // Need to get the SOAP method named called from httpRequest here... } </code></pre> <p><strong>UPDATE:</strong></p> <p>Here's the code I ended up using from the accepted answer (slightly modified). This code was tested and verified to work.</p> <pre><code>/// &lt;summary&gt; /// Returns the Soap method name called from the http request object. /// &lt;/summary&gt; public static string SoapMethod(HttpRequest httpRequest) { var bodyRequest = XDocument.Parse(GetDocumentContents(httpRequest)); if (bodyRequest.Root == null) return httpRequest.Url.AbsoluteUri; var element = bodyRequest.Root.Elements().Where(e =&gt; e.Name.LocalName == "Body").Elements().FirstOrDefault(); return element != null ? element.Name.LocalName : httpRequest.Url.AbsoluteUri; } /// &lt;summary&gt; /// Converts the input stream to a string for XML parsing. /// &lt;/summary&gt; private static string GetDocumentContents(HttpRequest request) { string documentContents; request.InputStream.Position = 0; using (var receiveStream = request.InputStream) { using (var readStream = new StreamReader(receiveStream, request.ContentEncoding)) { documentContents = readStream.ReadToEnd(); } } return documentContents; } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload