Serving default index.html page RRS feed

  • Question

  • Hello,

    I have written a WCF service and hosted in Windows service.

    When I start the windows service, I can access the WCF services at endpoint http:<ip-address>:<port>/<path-to-service>

    Apart from this, I want load default html page [index.html page that I have created] for a url like http:<ip-address>:<port>/web

    This index.html has to load bundle.js [which is in same folder of index.html]. FYI, I have bundled this web stuff using react js and webpack. So basically, I want to serve this index.html page for url http:<ip-address>:<port>/web

    And thereafter, I should be able to write POST/GET wcf services when I call them from index.html.

    How can I achieve this scenario?

    Thank you in advance!



    Monday, March 5, 2018 7:28 AM

All replies

  • What lead you to this unorthodox thing here?
    Monday, March 5, 2018 1:19 PM
  • After lots of searching, I think, I want to host a React Js application in windows service. 

    Now, When I start the windows service, it will register endpoint of my WCF service. 

    Along with this, I also want to start my web application [React js application] when I hit the url http://localhost:<portno>/web

    I hope, I described the requirement well.

    Thank you in advance again!

    Monday, March 5, 2018 1:37 PM
  • After lots of searching, I think, I want to host a React Js application in windows service. 

    I kind of doubt that you can do this. That is hosting a JavaScript library in a Windows service program. 

    Monday, March 5, 2018 6:55 PM
  • Hi Navnath,

    Based on your description, your issue is more related with hosting React Js in Windows Service.

    I did not find any information about this over the Internet. I am afraid it is impossible.

    Could you share us the information you found to host React in windows Service.

    Best Regards,

    Tao Zhou

    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact

    Tuesday, March 6, 2018 1:44 AM
  • Hello Tao Zhou,

    I also could not find the way to host React Js app in windows service, but I could find that we can host node js application in Windows Service. But nodejs app contains only javascript scripts and not html files and other assets. So, that way is not useful for me.

    What I have done so far is :

    1. I have created a ReactJs app and bundled it using webpack.

    2. After bundling, I am putting the result in some folder called C:\root.

    3. Now, this root folder contains index.html, bundle.js, and other image assets etc.

    4. I have created a WCF service which reads index.html content and return a Stream of html to browser as below:

    public Stream GetReqtifyWebPage() { OutgoingWebResponseContext response = WebOperationContext.Current.OutgoingResponse; String content = File.ReadAllText("F:\\Project\\RWA\\rwa\\public\\index.html");

    byte[] resultBytes = System.Text.Encoding.UTF8.GetBytes(content); response.ContentType = "text/html"; response.StatusCode = HttpStatusCode.OK; return new MemoryStream(resultBytes); }

    When I call this service from browser using url http://localhost:9090/web, it serves index.html successfully. 

    But this index.html try to load bundle.js. However, bundle.js is in C:\root folder, and index.html served by WCF service try to load it from url http://localhost:9090/bundle.js which throws an internal server error.

    Perhaps there maybe another solution for this instead of hosting the app in windows service. But I am not sure.

    Could you please help on this subject?

    Thank you again!

    Tuesday, March 6, 2018 4:04 AM
  • Just what are you trying to do here? Are you just looking for a way to serve HTML to a client from a Web service?

    If this is the case, who or what is the potential client?

    Tuesday, March 6, 2018 5:12 AM
  • Client is browser. I want to show html content in browser and also want to run javascript that html page wants to load.
    Tuesday, March 6, 2018 5:15 AM
  • Well, you had to have something on the client-side, like Ajax or something, to even make the call to the Web service from the browser. 

    What are you using to consume the service and why can't the JavaScript be hosted by the client?

    Tuesday, March 6, 2018 5:30 AM
  • I do not have any JavaScript client to make ajax call. 

    My requirement is that everything should be handled by WCF service hosted in Windows Service.

    Tuesday, March 6, 2018 5:35 AM
  • I don't think what you are trying to do is viable with WCF. Maybe you should be looking at Angular.js. Maybe you should be looking at .NET Core API. Maybe you should be looking at SignalR. 
    Tuesday, March 6, 2018 9:59 AM