I've tried, but I couldn't find any info about it.
Let's say that I have some webapis for my company that other devs (or qa) are going to use in theirs applications, and for easier use of my apis I'd like to create a library with client so that I can control how other devs are communicating with my api. So basically they can just install this package, add webapi url to configuration, inject necessary dependencies and use it. Is there any pattern, guidance etc. for creating such packages with client? I'm not talking about good practices how to create web api, rest api etc, but just this specific client package.
I've tried googling some tips or guidance about this (or maybe just generic instructions), but all I could find is how to create REST API...
You can use NSwag. With NSwag you can:
Generate Open API/Swagger specification from your Web API controllers. It is just a JSON document describing you API
Include an Html/JavaScript front end in your Web API application where users can see your API and invoke it.
Generate C# clients to invoke your web API.
Useful links:
https://github.com/RicoSuter/NSwag
https://learn.microsoft.com/en-us/aspnet/core/tutorials/getting-started-with-nswag?view=aspnetcore-7.0&tabs=visual-studio
Related
Morning Guys
I've been trying to manage an API created in asp.net WebApi, with the WSO2 Api Manager.
I've used the following doc with no sucess:
https://docs.wso2.com/display/AM200/Create+and+Publish+an+API.
The sample shows the use of ".asmx" endpoint, and in my case I have a simple http url (http://sample.enterprise.com/api/TestService), I want to http get a jsont result by WSO2 using an url like this.
Any clues ?
Thanks
WSO2 documentation is not great. The link you provided guides you through Designing and Publishing an API, but nowhere do I see any explanation for publishing an existing API. You essentially have two choices:
Choose Design New API and define the resources exactly as they are defined in your existing API (name, action, and required parameters much match exactly). Once you reach the Implement tab, choose Managed API and provide the production endpoint for your API. If this sounds overly complicated, you also have...
Choose I have an existing API and import your API's swagger definition from file or API endpoint. Keep in mind that importing swagger directly from your API requires connections between your Publisher node and the API endpoint if you have a distributed API Manager deployment strategy.
You can find tools to help you generate a swagger definition for your APIs here. For Web API projects like ours, you might want to consider using swashbuckle from the nuGet repository.
I am new to web services kind of things, wanted to know what are web services and how we can implement that in our asp.net project.
Searched on many sites but couldn't get the exact solution or a basic example of how to use that.
Could anyone please help.
There are many ways of implementing webservices. In .Net probably you want to have a look to:
Web API, if you want HTTP Rest webservices
WCF, if you want to implement SOAP services
In order to take that decision you need to think about the requirements of your services. Who are going to be the clients? Do you need distributed transactions?
I've setup a basic ServiceStack service that provides a centralised data hub for some complex reports.
We have a few different web apps that I want to (somehow) call on this service to get the required data and go on to display reports/graphs etc etc based on that information.
What I'm unclear on is how I actually 'get at' the ServiceStack data in C# as it is running as a completely separate website. (ie; our MVC app, which was created 2 years ago, has no link to ServiceStack at all just now).
I can see how I would be able to call via AJAX; but a requirement I have is being able to, in some instances, manipulate this data in C# directly.
Do I add a service reference like regular SOAP services? Or is there a better way to do this?
The best (and recommended) way to consume ServiceStack services from a .NET client is to use ServiceStack's .NET Service Clients.
The NuGet package that contains the Service Clients is:
Install-Package ServiceStack.Client
It's only dependencies are:
ServiceStack.Interfaces
ServiceStack.Text
For the least dependency you can consume Services with ServiceStack's Http Utils which is apart of ServiceStack.Text and has no dependencies, i.e:
Install-Package ServiceStack.Text
Also worth noting as ServiceStack just sends plain JSON/XML responses over HTTP you can use any .NET HTTP Client.
Please forgive me for this basic and a little theoretical question as I dont know much about web services.
I m not refering WCF service, I am reffering simple service in .net / C#. I want to know how to know is it soap or rest service ?
How we can change this type from Soap to Rest and vice versa ?
Thanks
XML Web Services (aka classic/legacy ASMX web services) should not be used for active development. If you must, there is a nice walkthrough on MSDN for adding Web references in more recent versions of Visual Studio (> 2005).
On the other hand, if your web service is truly Restful then you won't be able to create the equivalent of a service reference to it. You'll need to either use the HttpWebRequest, WebClient, or the new HttpClient from .NET 4.5 (also available from the Rest starter kit which is depreciated as well).
As an alternative if you are looking to implement a client that is able to handle both situations, I would recommend HttpWebRequest to POST to the SOAP (non-WCF) service. The problem with this method is you'll likely have to wrap the request in the SOAP wrapper yourself. Luckily there are examples of doing so on the net that you can at least use as a starting point.
ASMX services are build upon SOAP. REST is simply a HTTP based, You can access(or call) your business resources the way you access the normal URLs.
For ex in products catalog system, by using asmx you create set of functions to add,update,delete products. like addProduct(),updateProduct, etc..
But in REST, you will be having single point of access, like http:\mysystem\prodcuts. To retrieve,add,update,delete products, you will be using respective HTTP verbs (GET,POST,PUT,DELETE) on the same URL.
so,technically it's not possible to convert asmx(SOAP) service to rest...
I am looking to create a SOAP API using C# which I can then call using JavaScript. I use C# regularly but do not have any experience with creating API's. I would like to call the API using JavaScript as this will be used to submit form data from multiple websites not maintained by us.
If there is a better solution than SOAP I am open to suggestions.
If anyone can point me to examples or has any examples they can share I would appreciate it.
TIA
BrianKE
EDIT: I should have mentioned that I would to deploy a solution that will allow form data from multiple websites, not under our domain, to submit data directly to our database, hence the API. Perhaps there is a different way to handle this other than an API that I am not aware of.
If there is a better solution than SOAP?
If you are going to consume the API from javascript JSON is preferred. You may checkout this example which illustrates how to expose a JSON enabled WCF service for consumption from jquery AJAX.
Yes. You can.
Barring small issues/restrictions with XHR, it's perfectly "fine" to consume SOAP services from JS. The biggest issue is "dealing" with the XML, which can be more cumbersome than JSON (but it isn't bad if you use the correct tools such as XPath extractors). For my projects I use a small wrapper setup for the AJAX/XHR/SOAP call (not WSDL generated) that can take custom encoding/decoding functions.
Google searches shows several promising results/examples including JavaScript SOAP Client.
Note: If you need cross-domain access there are several methods including a proxy or the newer cross-domain XHR support (however, these require client and/or server support) or, depending on client, just really relaxed settings. These cross-domain considerations are generally no different than if using "REST" or other web-service APIs.