stratdev3 / SimpleW

SimpleW is a Simple Web Server library in NET (windows/linux/macos). It provides a cross-plateform framework for building web applications.
https://www.nuget.org/packages/SimpleW
MIT License
24 stars 2 forks source link

I am using EmbedIIO in my .NET MAUI application I would like to use SimpleW with SSL Support #1

Open samdubey opened 5 months ago

samdubey commented 5 months ago

Dear Team,

I want to create and implement self-signed certificate (https) and to have local http server inside .NET MAUI app for android, ios, maccatalyst and windows platform

How do I achieve this with SimpleW, kindly guide me in right direction

stratdev3 commented 5 months ago

Hi,

Actually SimpleW only support http cause my use case was "everything behind an https reverse proxy", (ie: nginx).

Until recently, i will have to embed SimpleW with https inside a C# android mobile app (the new xamarin.android rebranding).

I will look into this.

I have to decouple and refactor some class with interfaces to allow both NetCoreServer.HttpsServer and NetCoreServer.HttpServer use the Controller class.

Back in a few days

RagibNoor commented 5 months ago

Hi @samdubey could you please share a sample project with .net Maui and embedio recently I moved from Xamarin to Maui and I am using Embedio I am struggling to make it work after the upgrade

stratdev3 commented 5 months ago

@samdubey

I just release v12.0.0 which now support https protocol.

As you can see in the documentation it requires very few line changes from the http mode.

I made a basic working REST API example inside a fresh .net MAUI application. Just unzip MauiApp1.zip :

Run program and open up your browser to https://localhost:api/api/test (you need to bypass security and accept warning certificate cause it's self-signed).

Let me know if it is working for you

samdubey commented 5 months ago

Hi @samdubey could you please share a sample project with .net Maui and embedio recently I moved from Xamarin to Maui and I am using Embedio I am struggling to make it work after the upgrade

string localhotUrl = string.Format("http://localhost:{0}", AppSettings.FreePort); Task.Factory.StartNew(async () => { //using (var server = new WebServer(HttpListenerMode.EmbedIO, "http://*:8080")) using (var server = new WebServer(HttpListenerMode.EmbedIO, localhotUrl)) { //Assembly assembly = typeof(App).Assembly; //server.WithLocalSessionManager(); server.WithWebApi("/api", m => m.WithController(() => new StreamController())); //server.WithEmbeddedResources("/", assembly, "XaPlay.html"); await server.RunAsync(); } });

this code goes at App.xaml.cs

and I am using following method to get FreeTcpPort across platform: Windows, Maccatalyst, iOS and Android

static int FreeTcpPort()
{
    TcpListener l = new TcpListener(IPAddress.Loopback, 0);
    l.Start();
    int port = ((IPEndPoint)l.LocalEndpoint).Port;
    l.Stop();
    return port;
}
samdubey commented 5 months ago

@samdubey

I just release v12.0.0 which now support https protocol.

As you can see in the documentation it requires very few line changes from the http mode.

I made a basic working REST API example inside a fresh .net MAUI application. Just unzip MauiApp1.zip :

  • The main code is in the MainPage.xaml.cs file
  • self-signed certicate located in Resources\Raw\server.pfx

Run program and open up your browser to https://localhost:api/api/test (you need to bypass security and accept warning certificate cause it's self-signed).

Let me know if it is working for you

It ran into error:

image