Creating a custom API in ASP.NET [closed]
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the开发者_开发百科 question so it can be answered with facts and citations.
Closed 3 years ago.
Improve this questionI'm creating a site, and I need to create a basic API. Unfortunately I have no idea where to start.
My site will basically keep track of errors from other users' ASP.NET sites, and they can come to my site to filter through them, search through them, comment, resolve, etc. I need to create an API, where the user can insert a few lines of code in the Application_Error event in the global.asax file, and it will pass an exception object to my site to be stored.
It's the communicating between their site and my site that I don't understand and have no experience with.
Does anyone know of a good tutorial for creating a basic API like this?
You can create a page, handler, etc that receives data as an POST. Like twitter and other sites does.
Why make the API when there already is an API for this. You can use ASP.NET's webevents framework to catch this? Basically, each site could log the errors to a database, then your management app could read from the database for each site.
Check out ASP.NET health monitoring for more details.
It seems like you are trying to build a bug tracker. If you want to build it from scratch just for fun then check out health monitoring system of ASP.NET 2.0. Also, check out ELMAH it is super awesome.
Here is a screencast showing off how easy it is to setup ELMAH:
http://www.highoncoding.com/Articles/458_Plugging_Elmah_into_Web_Application_to_Catch_Unhandled_Exceptions.aspx
Just to re-iterate what's already been said, what you're trying to create is a web service - you have a number of options for implementing this from what basically amounts to a page you can post to through to notionally more complicated soap based stuff. I say notionally because if you're using ASP.NET at both ends then creating and consuming a service is relatively trivial.
For new development its suggested that you want to use WCF - which I find slightly harder than ASP.NET web services - basically run new project in Visual Studio and you'll get a framework which you really won't have to change much to create a service. At the client end there's a nice "add service" wizard that again will do the grunt work for you. Advantage of WCF is that you have more flexibility in the binding i.e. how the calling apps talk to the service.
For deployment I'd wrap your error logging code into an assembly - your users then just need to reference the assembly, and make a call setting the URL of the logging service and passing the error details.
For reference, you might want to go look at http://exceptioneer.com/ which is a service that does something similar to the setup you're trying to provide.
精彩评论