i want make web service by using HTTPlistener and all is works as expected but the issue is when i do refresh or get out from website and back it not displays for me the web.
int i = 0, k = 1;
HttpListener server = new HttpListener();
server.Prefixes.Add("http://10.0.0.7/");
server.Start();
Console.WriteLine("Server Running..");
try
{
string path = "C:/Users/James/Documents/EndProject/webproj/";
string[] files = Directory.GetFiles(path, "*.*", SearchOption.AllDirectories);
k = files.Length;
while (true)
{
for (i=0; i < k; i++)
{
HttpListenerContext context = server.GetContext();
HttpListenerResponse response = context.Response;
Console.WriteLine("Web URL: {0}", context.Request.Url.OriginalString);
byte[] buffer = File.ReadAllBytes(files[i]);
response.ContentLength64 = buffer.Length;
Stream st = response.OutputStream;
st.Write(buffer, 0, buffer.Length);
context.Response.Close();
}
}
}
The issue is enter image description here
it happens just if i trying approach again (F5,Refrash, or getting out and back again) how can i resolve it? Thanks