Using RESTful XML Web Services API - c#

I'm new enough to webservices and haven't used many. I need to use one for my latest task. It's an XML Web Services API, but I've no idea how to interface with it. Are there any tutorials/books available on using RESTful XML-based Web Services APIs anywhere? Or could anyone give me some pointers?
I don't really know where to start or what to look for.

It will depend on what version of .Net you can use. If 4.0 / 4.5 there is the HttpClient which will do the heavy lifting for you. If lower you need to look at making your own or using something like RestSharp. Restful Webservices are a surface unto themselves and it is a big topic to be general about. My suggestion is work through the restsharp samples and come back with any specific questions you have as general questions will yeild general answers.

Assuming you want to create a REST API,
Here are some links
asp.net
Code project tutorial
another one
It is based on ASP.NET MVC framework but the data returned by the controllers are not views but serialized information.
There is A loooooot of tutorials and documentation everywhere on the web.

Related

Is it good practice to create an API to handle calls to multiple APIs for integration

Brief overview, I am working with Visual Studio 2017 and .Net Core 2.1. I am about to begin development on a website which will handle integrating 3 existing pieces of software which our company uses.
I have created WCF services already for use by some of the applications I have developed, but for this project, there are multiple APIs which I will be utilizing. It's quite possible that I may need to use these APIs in other projects down the road.
I apologize if this is an opinionated question, but here it goes, do you think it is good design to develop one central API which wraps all the calls to the integrated system APIs? My thoughts were that in this way, I only have to write the code once for making the desired API calls and I can then add to this API as I see fit moving forward, ie. another system API is needed.
Please feel free to give advice, I am still learning and appreciate constructive advice. I am using this to get started on building my API using .Net Core 2.1, https://learn.microsoft.com/en-us/aspnet/core/tutorials/first-web-api?view=aspnetcore-2.1
If the APIs are related then yes it does make sense to create a single assembly to call those for you and deal with the responses. You'd then consume that assembly in all your other apps.
However, if the APIs are completely different and require different set ups, then it may make more sense to create an assembly wrapper for each to keep the concerns separate.
You don't want to confuse the APIs. If anyone was to look at your code or assembly, they should be able to say that it relates to what it describes and not have to guess.

REST Web Services using MVC, is it a good idea?

In .Net, I think about a web service as being a project type that you select from the menu, define your classes and methods then .Net does all this black magic under the hood to allow someone on the other side of the world to reference my web service and start coding using my classes and methods directly within their visual studio.
So having this preconceived notion, when looking at writing REST web services using MVC 3 (I know MVC 4 has a REST api baked in but am waiting for a full release) I'm wondering all the usual stuff like "is this a good idea", "will this stand up to heavy use" and "am I just writing toy web services that other developers will laugh at".
Now I think a lot of my anxiety is probably down to microsoft not having wrapped a big, overly complicated, bloated, shiny REST package around it yet. So I'm looking to have my anxiety relieved hopefully by people telling me yes MVC web services are perfectly good things to create.
Any help?
I've done it a few times, I am still using it in production and haven't got any complaints.
I actually think its a nice solution because it so simple to setup and maintain.
Not this incredibly xml-configuration-heavy wcf stuff..
You might want to also have a look at the WebAPI stuff that is in the process of being released (.net 4.5):
http://weblogs.asp.net/scottgu/archive/2012/02/23/asp-net-web-api-part-1.aspx
It's very much to do with exposing plain html services.
I would suggest you take a look at ServiceStack: http://www.servicestack.net/. It 's not only quite mature, but it can help you produce cleaner code.
It really does depend on what you plan on doing with your application. Yes, you could write an MVC website that doubles as a RESTful service. However, you are then tying your UI layer very closely to your logic layer, and that is what you really need to consider. I am working on an MVC site with a ServiceStack REST service (already mentioned by #Ioannis) . The reason that I did not make MVC my REST service is because I did not want any changes in my UI to potentially affect any third party application that might be using my logic service. So, as long as you carefully consider the ramifications of making your site also your RESTful service, then either decision could be ok. :)
As others have mentioned here, ServiceStack provides a solid, terse REST Web Services Framework allowing you to effortlessly develop typed, idiomatic C# API's end-to-end.
ServiceStack also includes a number of high-performance components that deeply integrates with ASP.NET MVC using the ServiceStack.Host.Mvc NuGet package.
To learn more about the benefits ServiceStack can add to your MVC project see:
http://www.servicestack.net/mvc-powerpack/

Building a C# Web API - REST

I am about to start a project in C#. I've never used c# and I was hoping I could get some implementation advice before I make a silly mistake and go down the wrong path.
What I am trying to achieve is basically having a C# application on a server that can be accessed via a Web API. This application will take in some string variables and then return a string. The application will be opening and running some installed programs (not c# programs).
I've read about WCF but I think at first glance this might be overkill as the API I am hoping to create will only have one or two request methods and will return a string.
What I am really looking for is advice on what I should be using, what to look into and even links to good tutorials on building web services with C# and how I can make the link between a web API to a C# app.
Thanks all for any advice.
Skip wcf and asmx. Instead just implement this stuff through generic handlers (.ashx) files.
You have complete control over what comes in and goes out without having to muck around with all the XML garbage. We did this a while back and haven't looked back.
In short, I'd use WCF if my endpoints were going to be something other than the web server. I'd use asmx if I had to deliver all of the responses back as XML AND I was assured only .net clients would be accessing it.
Generic handlers are like .aspx pages but without all of the overhead of the page lifecycle. It gives you get a context object that has access to all of the http post and query string variables and it's up to you to decide what to emit back.
They are simple to implement and have none of the "what was that config setting for again?" issues.
Here are a couple pretty good walkthroughs:
http://swindelles.com/2008/07/11/creating-rest-web-services-in-c-sharp/
http://www.codeproject.com/KB/aspnet/RestServicesInASPNET2.aspx
If you think WCF might be overkill you could implement a simple ASP.NET MVC application that returns data as JSON or XML.
http://omaralzabir.com/create_rest_api_using_asp_net_mvc_that_speaks_both_json_and_plain_xml/
update: Another excellent option is ServiceStack. I've used it and it's really nice to work with.
You could look into vanilla web services. I only briefly glanced at it, but this seems like a decent guide.
You really need to take a look to the WCF Data Services they are easy to implement
http://msdn.microsoft.com/en-us/data/bb931106
I first met them when I implemented the Dino Esposito examples in March 2010 MSDN Magazine
http://msdn.microsoft.com/en-us/magazine/ee336022.aspx
I recommend you first read the Dino Example.
For a simple Web API, WCF is overkill, clunky, operation orientated and designed for SOAP based services (it does Web HTTP, but that was an afterthought).
The new kid on the block is ASP.NET MVC Web API for lightweight web-orientated architectures. Prepare to see more and more of this young upstart.

REST based HTTP API - should I use WCF?

I would like to code a REST based HTTP API which is accessible from .NET and any other language like for example Python.
Should I use WCF for this? Or will that make the other languages harder to interop with my API?
I want the server to carry no state at all, and I want to be able to take advantage of HTTP persistent connections because a typical clinet will make many HTTP calls in a row. (maybe 2 hours straight of calls)
I am allowed to use .NET 4.
There is new stuff coming in WCF to support HTTP and REST. See, http://wcf.codeplex.com/
I wrote an intro blog post here http://www.bizcoder.com/index.php/2010/10/28/wcf-http/
WCF can do about anything you'll need, but it has a steep learning curve. The REST Starter Kit from Microsoft is very helpful.
Another .NET REST framework is OpenRasta - I haven't personally used it, but I've heard good things about it.
You should consider WCF, ASP.NET MVC and WCF Data Services. This article has a reasonable discussion on the pros and cons of each appproach:
http://weblogs.asp.net/cibrax/archive/2010/10/08/asp-net-mvc-wcf-rest-and-data-services-when-to-use-what-for-restful-services.aspx
See also this SO question: ASP.NET MVC and WCF
I suggest you try using WCF. Create a simple web service first (with only one call) and see if it suits your needs. Shouldn't take you long to do this. You may find this tutorial useful.

Consuming SOAP Web Services in Drupal from C# client

I want to make a client in C# in order to create Blog posts in Drupal, so the situation is the following. In Drupal i have Services module and soap_server both enabled and when i consume the wsdl file from http://example.com/services/soap?wsdl is recognizes it properly but i don't know what to do next... I'm stuck. The lack of documentation is a big disappointment for me. Does any one try this before? Any advise will be welcome ...
Maybe you chose this design for a specific reason that you did not illustrate in your question, but - just in case this is not the case - let me point out how you could leverage the built-in functionalities of Drupal and known API's to achieve what you want in less steps.
Use the Blog API module (shipped with Drupal Core) to expose widely known and well documented API's to the outside world, via the built-in XML-RPC interface.
Blog API exposes various blog-oriented API's, which are documented here, here and here.
Use code available online to implement the webservice consumer. I know nothing about C#, but from a quick google search, it seems such code is not difficult at all to be found. For example, here's some code from microsoft for metaweblog API's.
If for some reason you need or want to implement your own API with SOAP, then you should specify what your difficulties are. I assume you already created the SOAP services by following the documentation available online, and in particular this comment and this series of screencasts.
If this is the case, what is the difficult on the C# side? As stated before, I do not develop in C#, but - at least by googling it - it does seem like there is plenty of documentation and sample code available for this.
Eventually i will reinvent the wheel ... NuSoap library is much more simple to use. After extensive survey i have successfully accomplish to consume PHP web services based on NuSoap through C# client. I will make a custom module for drupal that will use NuSoap in order to call it from my C# client.

Categories