none
Self-hosting simple HTML page RRS feed

  • Question

  • I have a self-hosted web service, using System.ServiceModel.ServiceHost (i.e. WCF) with a NetTcpBinding binding, running beautifully within a Windows service. However, I'd like to put an information page at the site on the same port that a person could access in a browser.  I'd like to keep IIS out of the pictures, so I'd like to host the HTML page in the same service.  I assume this should be relatively simple, but I have no idea where/how to start.  How would I go about doing that?

    One thing I've read is that one can't use two different bindings on the same port.  Is that true?  If it is, then perhaps what I'm attempting to do is impossible.

    Thanks!

    Brad.


    • Edited by Pletzky Tuesday, September 27, 2016 11:27 PM More information
    Tuesday, September 27, 2016 10:37 PM

All replies

  • so I'd like to host the HTML page in the same service.

    A WCF service, a SOA solution,  job's is not to be displaying UI pages or forms of any sort nor is it a Windows service's job either.

    http://www.codeproject.com/Articles/515253/Service-Oriented-Architecture-and-WCF

     I'd like to keep IIS out of the pictures.

    If you want to do that, then you need to learn AngularJS.

    https://en.wikipedia.org/wiki/AngularJS

    Wednesday, September 28, 2016 1:18 AM
  • Hello Pletzky,

    Yes, you can have multiple endpoints on the same port.  Each endpoint can have different configuration.

    The biggest trick to returning html is to not encode the result.  Here are a couple of posts that should provide a starting point:

    http://stackoverflow.com/questions/13753815/return-html-format-on-wcf-service-instead-of-json-or-xml

    http://stackoverflow.com/questions/16592665/wcf-rest-svc-get-returning-html

    hope this helps!


    Cheers, Jeff

    Wednesday, September 28, 2016 3:29 AM
  • I think this is getting very close - those two links are quite useful, but they don't provide information on the service host configuration.  So, for example, if I set up my regular SOAP endpoints like this:

    soapServiceHost = new ServiceHost(typeof(MyWebService));
    soapServiceHost.AddServiceEndpoint(typeof(IMyWebService), new NetTcpBinding(), new Uri("net.tcp://myhost:12345/myserviceroot"));
    soapServiceHost.Open();

    how would I configure the second service host?  The examples will help me write "MyWebService" and "IMyWebService", but I'm not there yet.  I tried this:

    htmlServiceHost = new ServiceHost(typeof(HtmlService));
    htmlServiceHost.AddServiceEndpoint(typeof(IHtmlService), new WebHttpBinding(), new Uri(@"http://localhost:12345/HtmlResponse/"));
    htmlServiceHost.Open();
    

    but then I get an error saying "HTTP could not register URL http://+:12345/HtmlResponse/ because TCP port 12345 is being used by another application."

    Any ideas?

    Thanks!

    Brad.

    Wednesday, September 28, 2016 4:42 PM
  • Hello Brad,

    I have not had the time to look into this in detail but I did come across an interesting post:

    https://msdn.microsoft.com/en-us/library/ms734772.aspx?f=255&MSPPError=-2147217396

    It might be that port sharing is a feature of http but not tcp.  It looks like you can get this to work but is there a requirement that it must be the same port?


    Cheers, Jeff

    Wednesday, September 28, 2016 7:32 PM
  • Hmmm....  That looks interesting, but it looks like that's an operating system level change.  If it has to be done at the operating system level, then my interest plummets!

    Brad.

    Wednesday, September 28, 2016 9:50 PM
  • Hmmm....  That looks interesting, but it looks like that's an operating system level change.  If it has to be done at the operating system level, then my interest plummets!

    Brad.

    I agree.  I would really question the need to have this on the same port.  Single service I can understand but same port; maybe makes infrastructure simpler but usually you have to add a firewall rule per protocol anyways.

    Cheers, Jeff

    • Proposed as answer by Tony---- Thursday, October 6, 2016 9:34 AM
    Wednesday, September 28, 2016 10:12 PM