Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>You can access ASP.NET's HttpContext inside any WCF service hosted in ASP.NET as long as you turn on compatibility. This is done in two steps:</p> <ol> <li>Apply the AspNetCompatibilityRequirementsAttribute to your service class and set the RequirementsMode property to Required</li> <li><p>Make sure you enable compatibility by configuring the following:</p> <pre><code>&lt;system.serviceModel&gt; &lt;serviceHostingEnvironment aspNetCompatibilityEnabled=”true” /&gt; &lt;/system.serviceModel&gt; </code></pre></li> </ol> <p>Once you've done that, you can access the current HttpContext instance at any time using <a href="http://msdn.microsoft.com/en-us/library/system.web.httpcontext.current.aspx" rel="nofollow noreferrer">the static Current property</a>. For example:</p> <pre><code>foreach(HttpCookie cookie in HttpContext.Current.Request.Cookies) { /* ... */ } </code></pre> <p>Note that enabling integration with the ASP.NET runtime does incur some additional overhead for each request, so if you don't need it you can save some performance by not enabling it and just using the System.ServiceModel.Web runtime instead. You have access to pretty much all the information you need using the <a href="http://msdn.microsoft.com/en-us/library/system.servicemodel.channels.httprequestmessageproperty.aspx" rel="nofollow noreferrer">HttpRequestResponseMessageProperty</a> and <a href="http://msdn.microsoft.com/en-us/library/system.servicemodel.channels.httpresponsemessageproperty.aspx" rel="nofollow noreferrer">HttpResponseMessageProperty</a> classes.</p> <p>For more information on the subject, see <a href="http://msdn.microsoft.com/en-us/library/aa702682.aspx" rel="nofollow noreferrer">this section of MSDN titled WCF and ASP.NET</a>.</p>
 

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