Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6803575
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T19:21:40+00:00 2026-05-26T19:21:40+00:00

I have a self-hosted WCF service running as a windows service using the WebAPI

  • 0

I have a self-hosted WCF service running as a windows service using the WebAPI to handle the REST stuff and it works great.

I realise that I should really use IIS or similar to dish out actual web pages, but is there ANY way to get a service call to return “just” html?

Even if I specify “BodyStye Bare”, I still get the XML wrapper around the actual HTML, ie

<?xml version="1.0" encoding="UTF-8"?>
<string> html page contents .... </string>


[WebGet(UriTemplate = "/start", BodyStyle = WebMessageBodyStyle.Bare)]
public string StartPage()
{
    return System.IO.File.ReadAllText(@"c:\whatever\somefile.htm");
}

Is there any way to do this or should I give up?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T19:21:41+00:00Added an answer on May 26, 2026 at 7:21 pm

    The bodystyle attribute has no effect on WCF Web API. The example below will work. It’s not necessarily the best way of doing it, but it should work assuming I didn’t make any typos :-).

    [WebGet(UriTemplate = "/start")] 
    public HttpResponseMessage StartPage() {
        var response = new HttpResponseMessage();
        response.Content = new StringContent(System.IO.File.ReadAllText(@"c:\whatever\somefile.htm"));
        response.Content.Headers.ContentType = new MediaTypeHeaderValue("text/html");
        return response; 
    }
    

    It would probably make more sense to read the file as a stream and use StreamContent instead of StringContent. Or it is easy enough to make your own FileContent class that accepts the filename as a parameter.

    And, the self-host option is just as viable way to return static HTML as using IIS. Under the covers they use the same HTTP.sys kernel mode driver to deliver the bits.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a self hosted WCF Rest service that I am using to simulate
We have WCF services being self-hosted by a Windows Service inside our domain, using
System Description: I have a WCF service (self hosted in a windows service) which
I have a WCF self-hosted service in a Windows Forms application. I am going
I have a self-hosted WCF REST service based on the WebHttpBinding. One of the
I have a self-hosted WCF web service running, and an Android client application. I
I have a self-hosted WCF (as a Windows service), it has a web.config file.
I have an wcf winforms self-hosted app using nettcpbinding.(net.tcp://aaa.homeip.net:9388) The problem is windows 7
I have a Self-Hosted (Console App) WCF REST service with the following binding: WebMessageEncodingBindingElement
I have a single instance WCF service class that is self hosted using a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.