Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to start creating an application API in .NET

Tags:

c#

.net

vb.net

api

In the company I work for we have a desktop application developed in .NET that we like to open up some parts for other software developers.

I see it like some kind of public methods that other software can access. Is there any standard approach, best practices or other experience of this?

I guess you could do this with Win32 calls, C/C++ programming etc. But I'm mainly a .NET developer and have some years of experience programmming in mainly VB.NET but also some C#. I hope finding a way to do this within .NET. But it should be accessible for software developed in other languages.

Best regards/ Magnus

like image 573
Magnus Avatar asked Mar 10 '09 16:03

Magnus


People also ask

How do I create a .NET REST API?

Select the Visual C# | Web project type from the project type tree view, then select the ASP.NET MVC 4 Web Application project type. Set the project's Name to ContactManager and the Solution name to Begin, then click OK. In the ASP.NET MVC 4 project type dialog, select the Web API project type. Click OK.

What is API in ASP.NET C#?

ASP.NET Web API is a framework that makes it easy to build HTTP services that reach a broad range of clients, including browsers and mobile devices. ASP.NET Web API is an ideal platform for building RESTful applications on the . NET Framework.


2 Answers

There are two ways to go about this. The first involves using the Plug In / Module pattern. Start here for that.

A second way is to simply expose your API logic through well documented assemblies.

The way you pick really boils down to how you want it implemented. For example, Adobe Photoshop uses the plug-in pattern to great extent. MS Office uses both plug-ins as well as provides an object interface for working with the application.

UPDATE: Objects in .Net assemblies can be exposed to be consumed by external applications simply by setting the objects scope to Public. This includes windows forms, business objects, enum's, etc.

Just think about it from the external developer's perspective. What information will they need to have in order to be successful at extending / controlling your product? Whatever that is, put it in the help file.

Also, make use of the auto-documentation features of .Net. This includes adding xml documentation the the IDE already knows how to read and display via intellisense. For example:

/// <summary>
/// Gets all active documents for the specified customer.
/// </summary>
/// <param name="customerId">The Id of the customer.</param>
/// <returns>A list of documents for this customer.</returns>
public static List<Document> GetDocuments(int customerId)
{
    //... do something ...
}
like image 87
NotMe Avatar answered Sep 29 '22 22:09

NotMe


Create an API class that exposes what functions you want people to have access to and Register it for COM interop project ->properties -> build -> Register for COM interop

like image 31
Bob The Janitor Avatar answered Sep 29 '22 23:09

Bob The Janitor