unosquare / embedio

A tiny, cross-platform, module based web server for .NET
http://unosquare.github.io/embedio
Other
1.45k stars 175 forks source link

The return array is empty. #596

Closed simphonydeveloper closed 3 months ago

simphonydeveloper commented 3 months ago

Describe the bug

this is my configuration.

        var server = new WebServer(o => o
                .WithUrlPrefix(url)
                .WithMode(HttpListenerMode.EmbedIO))
            // First, we will configure our web server by adding Modules.
            .WithLocalSessionManager()
            .WithWebApi("/api", m => m
            .WithController<BasicController>())
            //.WithModule(new WebSocketChatModule("/chat"))
            //.WithModule(new WebSocketTerminalModule("/terminal"))
            //.WithStaticFolder("/", HtmlRootPath, true, m => m
            //.WithContentCaching(UseFileCache)) // Add static files after other modules to avoid conflicts
            .WithModule(new ActionModule("/", HttpVerbs.Any, ctx => ctx.SendDataAsync(new { Message = "Error" })));

        //server.Options

        // Listen for state changes.
        server.StateChanged += (s, e) => {
            Console.WriteLine($"WebServer New State - " + e.NewState);
            $"WebServer New State - {e.NewState}".Info();
        };

Embedio

Screenshots image

Desktop (please complete the following information):

simphonydeveloper commented 3 months ago

I have found a solution https://github.com/unosquare/embedio/issues/467

 public static async Task SerializationCallback(IHttpContext context, object data)
 {
     Validate.NotNull(nameof(context), context).Response.ContentType = MimeType.Json;
     using ( var text = context.OpenResponseText(new UTF8Encoding(false)))
     {
         await text.WriteAsync(JsonConvert.SerializeObject(data, new Newtonsoft.Json.JsonSerializerSettings()
         {
             ReferenceLoopHandling = ReferenceLoopHandling.Serialize
         })).ConfigureAwait(false);
     }

 }
 var server = new WebServer(o => o
         .WithUrlPrefix(url)
         .WithMode(HttpListenerMode.EmbedIO))
     // First, we will configure our web server by adding Modules.
     .WithLocalSessionManager()
     .WithWebApi("/api", SerializationCallback, m => m.WithController(() => new BasicController()))
     .WithModule(new ActionModule("/", HttpVerbs.Any, ctx => ctx.SendDataAsync(new { Message = "Error" })));