Git Product home page Git Product logo

Comments (15)

mariodivece avatar mariodivece commented on August 17, 2024 1

Take a look at this sample code I have created for you. It uses a background worker to host the web server in your winforms app.
https://www.dropbox.com/s/yzbo365m8hlqrzf/WindowsFormsApplication1.zip?dl=0

from embedio.

geoperez avatar geoperez commented on August 17, 2024

Let me try to reproduce it.

from embedio.

geoperez avatar geoperez commented on August 17, 2024

I found some minor issues in the basic sample that I'll fix. I created a console app with the Nuget and the next code and it's working fine:

namespace Company.Project
{
    using System;
    using Unosquare.Labs.EmbedIO;
    using Unosquare.Labs.EmbedIO.Log;
    using Unosquare.Labs.EmbedIO.Modules;

    class Program
    {
        /// <summary>
        /// Defines the entry point of the application.
        /// </summary>
        /// <param name="args">The arguments.</param>
        static void Main(string[] args)
        {
            var url = "http://localhost:9696/";
            if (args.Length > 0)
                url = args[0];

            // Our web server is disposable. Note that if you don't want to use logging,
            // there are alternate constructors that allow you to skip specifying an ILog object.
            using (var server = new WebServer(url, new SimpleConsoleLog()))
            {
                // First, we will configure our web server by adding Modules.
                // Please note that order DOES matter.
                // ================================================================================================
                // If we want to enable sessions, we simply register the LocalSessionModule
                // Beware that this is an in-memory session storage mechanism so, avoid storing very large objects.
                // You can use the server.GetSession() method to get the SessionInfo object and manupulate it.
                // You could potentially implement a distributed session module using something like Redis
                server.RegisterModule(new LocalSessionModule());

                // Here we setup serving of static files
                server.RegisterModule(new StaticFilesModule("c:/web"));
                // The static files module will cache small files in ram until it detects they have been modified.
                server.Module<StaticFilesModule>().UseRamCache = true;
                server.Module<StaticFilesModule>().DefaultExtension = ".html";
                // We don't need to add the line below. The default document is always index.html.
                //server.Module<Modules.StaticFilesWebModule>().DefaultDocument = "index.html";

                // Once we've registered our modules and configured them, we call the RunAsync() method.
                // This is a non-blocking method (it return immediately) so in this case we avoid
                // disposing of the object until a key is pressed.
                //server.Run();
                server.RunAsync();

                // Fire up the browser to show the content if we are debugging!
#if DEBUG
                var browser = new System.Diagnostics.Process()
                {
                    StartInfo = new System.Diagnostics.ProcessStartInfo(url) { UseShellExecute = true }
                };
                browser.Start();
#endif
                // Wait for any key to be pressed before disposing of our web server.
                // In a service we'd manage the lifecycle of of our web server using
                // something like a BackgroundWorker or a ManualResetEvent.
                Console.ReadKey(true);
            }
        }
    }
}

from embedio.

srad avatar srad commented on August 17, 2024

Thanks for the quick reply, I still get an exception which I thought was related to the access rights level to the file system, but raising the level to admin didn't made it go away. Any idea what this is?

My VS is in German, but the trace should be readable:

Web server prefix 'http://localhost:9696/' added.
Finished Loading Web Server.
"App.vshost.exe" (CLR v4.0.30319: App.vshost.exe): "C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\mscorlib.resources\v4.0_4.0.0.0_de_b77a5c561934e089\mscorlib.resources.dll" geladen. Das Modul wurde ohne Symbole erstellt.
Started HTTP Listener
System.Net.HttpListenerPrefixCollection
Listener Closed.
System.ObjectDisposedException: Auf das verworfene Objekt kann nicht zugegriffen werden
(object can't be accessed).
Objektname: "System.Net.HttpListener".
   bei System.Net.HttpListener.CheckDisposed()
   bei System.Net.HttpListener.EndGetContext(IAsyncResult asyncResult)
   bei System.Threading.Tasks.TaskFactory`1.FromAsyncCoreLogic(IAsyncResult iar, Func`2 endFunction, Action`1 endAction, Task`1 promise, Boolean requiresSynchronization)
--- Ende der Stapelüberwachung vom vorhergehenden Ort, an dem die Ausnahme ausgelöst wurde ---
   bei System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   bei System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   bei System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
   bei Unosquare.Labs.EmbedIO.WebServer.<<RunAsync>b__4>d__7.MoveNext()

from embedio.

geoperez avatar geoperez commented on August 17, 2024

It's seem like the tcp port can not be open. What Windows version are you
using?
On May 10, 2015 3:44 PM, "Saman" [email protected] wrote:

Thanks for the quick reply, I still get an exception which I thought was
related to the access rights level to the file system, but raising the
level to admin didn't made it go away. Any idea what this is?

My VS is in German, but the trace should be readable:

Web server prefix 'http://localhost:9696/' added.
Finished Loading Web Server.
"App .vshost.exe" (CLR v4.0.30319: LernBar Studio.vshost.exe): "C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\mscorlib.resources\v4.0_4.0.0.0_de_b77a5c561934e089\mscorlib.resources.dll" geladen. Das Modul wurde ohne Symbole erstellt.
Started HTTP Listener
System.Net.HttpListenerPrefixCollection
Listener Closed.
System.ObjectDisposedException: Auf das verworfene Objekt kann nicht zugegriffen werden
(object can't be accessed).
Objektname: "System.Net.HttpListener".
bei System.Net.HttpListener.CheckDisposed()
bei System.Net.HttpListener.EndGetContext(IAsyncResult asyncResult)
bei System.Threading.Tasks.TaskFactory1.FromAsyncCoreLogic(IAsyncResult iar, Func2 endFunction, Action1 endAction, Task1 promise, Boolean requiresSynchronization)
--- Ende der Stapelüberwachung vom vorhergehenden Ort, an dem die Ausnahme ausgelöst wurde ---
bei System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
bei System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
bei System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
bei Unosquare.Labs.EmbedIO.WebServer.<b__4>d__7.MoveNext()


Reply to this email directly or view it on GitHub
#10 (comment).

from embedio.

mariodivece avatar mariodivece commented on August 17, 2024

I would also suggest changing the port. Go for a url prefix such as:

http://localhost:49618/

From: Geovanni Perez [mailto:[email protected]]
Sent: Sunday, May 10, 2015 3:48 PM
To: unosquare/embedio
Subject: Re: [embedio] Basic example doesn't serve static files (#10)

It's seem like the tcp port can not be open. What Windows version are you
using?
On May 10, 2015 3:44 PM, "Saman" <[email protected]mailto:[email protected]> wrote:

Thanks for the quick reply, I still get an exception which I thought was
related to the access rights level to the file system, but raising the
level to admin didn't made it go away. Any idea what this is?

My VS is in German, but the trace should be readable:

Web server prefix 'http://localhost:9696/' added.
Finished Loading Web Server.
"App .vshost.exe" (CLR v4.0.30319: LernBar Studio.vshost.exe): "C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\mscorlib.resources\v4.0_4.0.0.0_de_b77a5c561934e089\mscorlib.resources.dll" geladen. Das Modul wurde ohne Symbole erstellt.
Started HTTP Listener
System.Net.HttpListenerPrefixCollection
Listener Closed.
System.ObjectDisposedException: Auf das verworfene Objekt kann nicht zugegriffen werden
(object can't be accessed).
Objektname: "System.Net.HttpListener".
bei System.Net.HttpListener.CheckDisposed()
bei System.Net.HttpListener.EndGetContext(IAsyncResult asyncResult)
bei System.Threading.Tasks.TaskFactory1.FromAsyncCoreLogic(IAsyncResult iar, Func2 endFunction, Action1 endAction, Task1 promise, Boolean requiresSynchronization)
--- Ende der Stapelüberwachung vom vorhergehenden Ort, an dem die Ausnahme ausgelöst wurde ---
bei System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
bei System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
bei System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
bei Unosquare.Labs.EmbedIO.WebServer.<b__4>d__7.MoveNext()


Reply to this email directly or view it on GitHub
#10 (comment).


Reply to this email directly or view it on GitHubhttps://github.com//issues/10#issuecomment-100699325.

from embedio.

srad avatar srad commented on August 17, 2024

I'm on Windows 8.1, VS 2013, .net 4.5
@mariodivece Changing the port didn't changed it, still the same exception. I tried a few ports.

from embedio.

mariodivece avatar mariodivece commented on August 17, 2024

Quick question: Are you trying from the nuget package or from source? If from source, can you do a step-through and let us know which line breaks it? If from nuget can you send us the version number pls?

Please forgive the brevity and typos. Message sent from a mobile device.


From: Samanmailto:[email protected]
Sent: ‎5/‎10/‎2015 3:53 PM
To: unosquare/embediomailto:[email protected]
Cc: Mario Di Vecemailto:[email protected]
Subject: Re: [embedio] Basic example doesn't serve static files (#10)

I'm on Windows 8.1, VS 2013, .net 4.5
@mariodivecehttps://github.com/mariodivece Changing the port didn't changed it, still the same exception. I tried a few ports.


Reply to this email directly or view it on GitHubhttps://github.com//issues/10#issuecomment-100700106.

from embedio.

srad avatar srad commented on August 17, 2024

I used the nuget package, version: 1.0.3
I could also try using the source code, but I'm not a full c# programmer, I'll try to figure it out.

from embedio.

srad avatar srad commented on August 17, 2024

Hold on, I didn't realized that the example was only supposed to be run from a console application. But still the exception irritated me.

However I created a console only application and it's seems to be OK. I ran it within an forms project.

Is there any guideline how I should/can embed this inside such an existing application, or can you give me some tips? Do the I have to keep the webserver running in a loop in a background or how do I handle this.

from embedio.

mariodivece avatar mariodivece commented on August 17, 2024

I created a new project from embedio package 1.0.3, added index.html to c:\web and it worked just fine... I'm attaching the zip file with the VS 2013 project. Can you let us know if it works?
https://www.dropbox.com/s/0zkg1vwn5qrsiy3/ConsoleApplication1.zip?dl=0

from embedio.

mariodivece avatar mariodivece commented on August 17, 2024

What kind of application are you writing? You don't have to run it in a console app. In fact we use it in Windows services and linux daemons. If you'd like to run it in say, a WPF app or a WinForms app, you'd just spawn a new thread and leave it there.

from embedio.

srad avatar srad commented on August 17, 2024

It's a desktop application which hosts a local web application and I want to implement a REST API to the web server, so I can move the application later online and retain the web application implementation, once the online service is done.

In the ideal case I would keep the current web server implementation I'm working on (and run on mono) and only change the existent legacy backend.

from embedio.

srad avatar srad commented on August 17, 2024

Got it. Guys you are just awesome and really helpful thank you! I might be annoying you in the near future again, since I'm playing with you project. Thanks again :)

from embedio.

mariodivece avatar mariodivece commented on August 17, 2024

You bet, and good luck with your project! Closing this one down.

from embedio.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.