Click here to Skip to main content
13,902,931 members
Rate this:
Please Sign up or sign in to vote.
See more:
Good afternoon everybody; I have to develop a VB Net program to consume a REST Web service, and I´ve never done this before, so I´m a little nervous.

There are the facts.

- I plan to use the HttpWebRequest class. I also thought of using the WebClient class, but I located already developed code of the late so I decided to use it.

- I have to cancel an electronic invoice already stamped, so I also have to make the necessary updates in our ERP system, but for now, I just want to see the web Consuming functions.

- I have to download the XML File of the cancellation acknowledgment (in spanish: "Acuse de Cancelación") and the PDF file also, and store them in our network.

Somebody thinks it would be better to use the WebClient class, or another ?

Can anybody give me a hint or advice about where to look for the most specific possible example of code ?, or any sugestion, or where to look for a quick introduction ?

Thanks in advance for any help, fellows.

What I have tried:

I´ve been studying and searching thru the Internet about REST services and how to consume them, answers and enough hints to be able to start coding, now I have to proceed to development.

I also decided to use the HTTPWebRequest class based and what I saw and the the conditions of our installation.
Updated 25-Jun-18 8:40am
Richard Deeming 26-Jun-18 11:24am
If it's a real REST service, you might want to look at RestSharp[^], which handles a lot of the repetitive low-level stuff for you.
Miguel Altamirano Morales 27-Jun-18 12:42pm
Thank you Richard; is that a third-party tool ?, do I need to download it or it´s Microsoft's ?
Richard Deeming 27-Jun-18 12:45pm
It's an open-source third-party library. You can install it from NuGet[^], or download the source[^], which is under an Apache 2.0 license.
Miguel Altamirano Morales 27-Jun-18 14:10pm
Thank you very much

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

So what you are trying to accomplish is pretty straight forward but Im guessing you are getting nervous because you are viewing the project as a whole instead of breaking down what you want to accomplish into smaller pieces.

Assuming when you say you need to download an XML File and you aren't talking about the API returning XML as its response, whether you are downloading an XML file or a PDF file...the root of what you are doing is still downloading a file.

First step then is to figure out how to download a file. Whether you use HttpWebRequest class, WebClient or doesn't matter. They will all do what you need to do so just pick whatever you feel is best and allows you to accomplish your end goal the best/easiset way possible.

Some links to downloading a file

Download File From URL Code VB.NET - Stack Overflow[^]

WebClient.DownloadFile Method (String, String) (System.Net)[^]

How to: Download a File in Visual Basic | Microsoft Docs[^]

how to download a file in VB - Google Search[^]

Your second problem it looks like is you need to call an API exposed by your ERP system. Thats pretty simple, all you need to do is google "post to web service in VB".

Setup POST REST Webservice with and -[^]

Can I do a POST in to a web service?[^]

Then bringing it together, just use the code to download the file along with whatever code your write to process the XML or PDF files, and include the call back to your ERP system and as long as I understood you correctly, you've accomplished what you needed to do.

As for the difference between HttpWebRequest and WebClient...there is plenty of stuff on google as to what the difference is but essentially WebClient is just an abstraction built on top of HttpWebRequest. If you don't want to worry about as much plumbing necessarily in terms of what the request is doing, use WebClient...otherwise there is nothing wrong with utilizing either class for API calls.
Miguel Altamirano Morales 25-Jun-18 14:47pm
Tahnks a lot David; I´ll spend the entire afternoon reading all this stuff you suggested me.
I guess the first thing I have to do is to pass the necessary credentials and certains parameters to the service, such as: the uuid of the invoice to cancel, the username, and the password. I hope the information about how to do it can be found in these documentation.

I´m nervous only because this is the first time I have to do a VB program to accomplish this and I'm under a lot of pressure.

Yes, I have to donwload a XML and a PDF file, and update my tables due to the cancellation.

Thank you very much !!!
David_Wimbley 25-Jun-18 23:29pm
Hope it helps, since I'm not familiar with your API only you are going to know how the authentication works (Ex: is it bearer token authentication? basic auth?) so you'll just have to google the type of authentication and then append VB to the end of your google search. Your API is likely straight forward so there is sure to be plenty of documentation that is just a short google search away.

Good luck.
Miguel Altamirano Morales 26-Jun-18 12:07pm
Thank you very much, David, I´ll let you know (if you let me do so) whatever happens. Our Vendor already gave me enough information about their web Service, I needed that also.

I started to make the changes our ERP needs and then I´ll proceed to consume the service; I have a bit of code already done; I'm going to check how to send data in my request; I think I saw something about it in the pages you sent me yesterday.
Such a nice person you are.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Cookies | Terms of Service
Web05 | 2.8.190306.1 | Last Updated 25 Jun 2018
Copyright © CodeProject, 1999-2019
All Rights Reserved.
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100