![]() This tip/trick will show you how to use a self hosted RESTFUL WCF end point as a lite web server. This is NOT intended as a replacement for IIS or any other full featured web server. Instead, it's the beginning of a lite, basic functional web server that can be deployed as background service. I needed the ability to host a web site without installing IIS or any other 3 rd party web servers. Using WCF with URL wildcards inside a Windows background service, I came up with exactly what I needed! Using the Code I wanted it to be lite with a small foot print. I started with a Windows Service project template. I'm not going to get into how to build a Windows service project here. There is plenty of documentation on how to build Windows service projects. ( string.Format(pageFormat, errorCode, message))) Private Stream GetErrorResponseStream( int errorCode, string message) ResourceStream = this.GetErrorResponseStream( 500, " Internal Server Error") ResourceStream = new MemoryStream(File.ReadAllBytes(Path.Combine(basePath, path))) Ĭatch (System.IO.DirectoryNotFoundException) ResourceStream = this.GetErrorResponseStream( 404, " Not Found") String mimetype = (Path.GetExtension(path)) This.baseMimetypeHelper = MimetypeHelper.GetInstance() Private MimetypeHelper baseMimetypeHelper = null īasePath = Path.Combine(, " I'm going to focus on the WCF portion on our lite web server. Here is the portion of our app config related to the WCF end point. ![]() You guys can choose songs based on the intellectual spelling selection mode. It basically supports all major file formats of music starting from CDG, MKV, MP4, FLV, ASF, VOB as well as RMVB. This is a pretty standard serviceModel section. KJams also has commercial use and folks mostly use it in pubs and clubs and discotheques as well. The important points here are the endpoint binding type is " webHttpBinding" which is key for a RESTFUL end point. In the code snippet above, if a user navigates to the root of your site, the path will be null and we return the default page.Ĭopy Code index.html In our settings, we have a default page in the event a user browses to the root of your web site which is what most people do, I.E. In order for the server to return the correct mimetype based on the users request, we need a dictionary of types. String type = mimetype.Attribute( " type").Value String extension = mimetype.Attribute( " fileExtension").Value IEnumerable mimetypeElements = element.Element( " MimeTypes").Elements() įoreach (XElement mimetype in mimetypeElements) Public static MimetypeHelper GetInstance() Private static MimetypeHelper INSTANCE = null Below is a good starting point for the most common mimetypes for most web sites. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |