Some advice to have restful service in wisej?

1
0

Hi!
Some advice to have restful json service in wisej?
Maybe Nancy integration? Or another approach (I’m using localdb and i want to know if calls to restful service is posible) (I need restful service because i have some IoT devices to connect with)

http://nancyfx.org/
https://www.nuget.org/packages/Nancy/
Thanks in advance!

  • You must to post comments
0
0

Hi David.
You need both nuget packages
Install-Package Nancy
Install-Package Nancy.Hosting.Aspnet

Last fixes you issue about -> “Could not load type ‘Nancy.Hosting.Aspnet.NancyHttpRequestHandler”

  • You must to post comments
0
0

Hi David,

I had a quick lock at the sample but it’s unclear to me what you need to do. The sample references Nancy but uses ASP.NET WebApi. It uses Nancy only for JSON serialization but it also references Newtownsoft. It also uses static properties in a non-static lass “output” to save user authentication. Static properties will be available to all sessions – if one client is authorized then all clients become authorized (I don’t know if this was intended).

In general web api routing, whether using Nancy, WebApi or Web Handlers (ashx) is not hampered or managed by Wisej at all. Static routing is entirely up to the web server and the routing framework.

Wisej is a stateful system. Each client (browser) creates a session on the server. If a stateless api call from a specific client needs to access the Wisej session, it must pass back the session id as part of the URL. If that is what you are trying to do I can send you an api sample using either Nancy, WebApi, or Web Handlers.

Let me know which routing system you prefer.

  • David .
    Can send you please send an api sample using Nancy.
  • You must to post comments
0
1

This is the simplest code to do a basic handler that does basic REST / HTTP API POST  [That is transfer data from an application up to a web service – database]

Attached is WebApi.sln

a. Winform POST json object to http://localhost:xxx/api/a/b

b. WebApi Handler decodes JSON POST to object and can then store to database/etc.  Code gets very specific to your api once you get started (swagger / api editors )

Seems Nancy is a wrapper that makes syntax easier to read when decoding/encoding your data

Let me know if you can figure out how the Application.MainPage can access to WebApi object so you dont have to go via database with SignalR to alert app/ or poll database.

Attachment
  • You must to post comments
0
0

I have tried many ways to implement basic RESTful API function like

http://volkanpaksoy.com/archive/2015/11/11/building-a-simple-http-server-with-nancy/

https://www.codeproject.com/tips/894355/microservice-net-create-micro-services-easily-with

I have run into issues with System.Web.HttpException: Could not load type ‘Nancy.Hosting.Aspnet.NancyHttpRequestHandler’ from web.config

A simple working WiseJ example with RESTful implementation would be greatly appreciated.

 

 

 

  • David .
    Thanks Ser Gar, Install-Package Nancy.Hosting.Aspnet fixed issue Could not load type issue :)
  • You must to post comments
0
0

You can use Nancy. And if you need to retrieve the state (Nancy is stateless) you can use Application.RestoreSession(HttpContext.Current); See sample below:

public class SampleModule : Nancy.NancyModule
{
public SampleModule()
{
Get[“/products/{id}”] = args =>
{
Application.RestoreSession(HttpContext.Current);
Application.OpenForms[“Window1”].Text = “Hello from Nancy!”;

return “Hello World!”;
};
}
}

This is web.config:

<handlers>
  <add name="wisej" verb="*" path="*.wx" type="Wisej.Core.HttpHandler, Wisej.Core" />
  <add name="Nancy" verb="*" path="*" type="Nancy.Hosting.Aspnet.NancyHttpRequestHandler" />
 </handlers>

And of course make sure that “/” is not a route.

 

  • Ser Gar
    Wow! Excelent! I will try it.
  • You must to post comments
Showing 5 results
Your Answer

Please first to submit.