Console Web Service app using HandleSpecialURL?

Hello all.

Please forgive my naivete. I am wondering if I can create a console web service app that uses the HandleSpecialURL event, same as the sample “Web Services Server”?

This sample is a web app, which I do not need, since I am looking to create a headless app.
If this is possible, but the starting sample is not the correct one to use as a guide, can anyone suggest the best fit for a sample?
If it is the best sample, how to change from a WebApplication super to a Console Application super - I tried it and the app really did not want to change supers… also could not delete session

Thanks all!
Tim

A web app will quite happily run as a console app without any changes (at least on Windows with the ports open in the firewall). It does seem to need a “home” page which I guess is not uncommon even if it only static & say’s “nothing happening here - move along”. I’m guessing though that in most cases you’ll want to register the user & validate their access of the service, maybe also rate limit their access to avoid crashing the service.

Why not use a headless web app for this? Or make the “main page” an admin login to administer the app? You could write code to create your own HTTP service, but WebApplication already does the heavy lifting for you. A WebApplication is pretty much a console app with http built in.

Hi Guys,

Thank you for your responses!

This app is only to serve data from a local SQLite database across a LAN. This is in response to my post:
link text

One of my remote apps, calls on the web services app on a remote (LAN in this case) device, to have some database records sent to it. Just like the eddies electronics sample.

If I understand what you guys are writing, it is safe to do a web app, but know that the page will not appear (and I do not want it TO appear!).

That really is the only reason to convert to console app, I don’t want or need a page to be served. If having a page but not using it or showing it is OK, then this is a moot point.

Thoughts?
Tim

Scratching head… what page do you mean? You “ask” your app something and it delivers something back. Page, error, just an “ok”, whatever. Or you explain with a bit more detail what you want to do.

Tim it’ll work fine. You can just deliver a blank page to whoever may try to browse the site or even better redirect them to the company website. Your special (or as I prefer API) stuff does not reference this “home” page.

You may want to take a look at Aloe

If you look at the Eddies Web Services sample, it is a web app, with a single page. I was starting off with this, but do not want/need the page to be displayed.

@Tim Kearns - thanks for the tip! I’ll have a look at that.
Tim

If you always return True in WebApplication.HandleURL then you’ll prevent the standard web app pages from appearing at all. Then you can just return error JSON, a 404 or whatever you want for your API.

I’m thinking something like this:

[code]Function HandleURL(Request As WebRequest) Handles HandleURL as Boolean
Select Case Request.Path
Case “MyAPI1”
// Do something
Case “MyAPI2”
// Do something
Else
// Return an error as this is an invalid API call
Dim j As New JSONItem
j.Value(“Error”) = “Invalid API request”

Request.Print(j.ToString)

End Select

Return True
End Function[/code]

@Paul - so to use HandleURL it should be in a web app. But as you state, don’t worry about the web page, just return true then nothing will be sent other than whatever is replied to in my code -

Thanks,
Tim

That’s right.

Is it also true that the other end does not have to be part of a web app? I believe this correct since the eddies (EEWS) is a desktop app.

Just thought I could do the same on the server side too but maybe not…? Ideally both would be a console app… at least in my case.

Tim

The other end would use an HTTPSocket to talk to your web app and make requests. I have service apps that httpsocket to api endpoints to exchange information. So, yes, a console app can do it. And to be clear, a web app is a console app, so both ends are actually console apps.

Thanks Tim.
I know that a web app is a special console app, but thought there might be something special in the web app sauce!