Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I know this is an old post, but for a service that will only be hosted in IIS, here is an easy way to return html:</p> <pre><code>[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Required)] public Stream getHtml() { // get the html var html = DoSomethingToGetHtml(); //Not a built-in .Net method ;) // we want our result interpreted as plain html WebOperationContext.Current.OutgoingResponse.ContentType = "text/html; charset=utf-8"; // create a stream from our html because trying to return a string adds an extra header tag // to the response. Returning a stream returns the html by itself var result = new MemoryStream(Encoding.UTF8.GetBytes(html)); // return the result return result; } </code></pre> <p>This code requires the following in the web.config hosting the service:</p> <pre><code>&lt;system.serviceModel&gt; &lt;!-- enable HttpContext.Current by setting aspNetCompatibilityEnabled=true--&gt; &lt;serviceHostingEnvironment aspNetCompatibilityEnabled="true"/&gt; &lt;behaviors&gt; &lt;endpointBehaviors&gt; &lt;behavior name="webHttpEnabled"&gt; &lt;webHttp/&gt; &lt;/behavior&gt; &lt;/endpointBehaviors&gt; &lt;/behaviors&gt; ... &lt;system.serviceModel&gt; </code></pre> <p>In the configuration for the service, set <code>behaviorConfiguration="webHttpEnabled"</code>.</p> <p>Returning html in this way limits the reusability of the service a bit, but it's an easy way to solve the problem if you're reasonably sure the service will always be hosted in IIS.</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