VB.NET from Dummies – How to access Webservices
In this little guide, i try to explain how to use webservice in VB.NET, well actually the you can use it in other .NET platform, but you have to modify the code a little bit.
Why you use webservice?
There is a lot of reason, my case is I have to get a a realtime gold price for my apps. In this example I want to convert how much the price for one troy ounce of gold (XAU) in Rupiah (IDR).
How you do it?
Simple, or rather, more simple than I imagine.
First you must find a webservice of your need. In my case, it is in here. In Webservicex.net you can find a lot of webservices at hand. And their website, they claims to have 4 million transaction a day. Good enough for me.
Second, you have to identify the service you need. In my case, it is on here, Currency converter.
Third, you add that service to your .NET project. Just add web reference on your project, type the complete path to the webservice. Then follow the wizard. Microsoft is good enough to create the wizard for you.
Fourth, show me the code.
The it’s the coding time. First you have to create an instance for the webserivce. Then you must specify proxy setting and credentials (if your apps behind proxy like mine), then you’re ready to go. Oh… one more thing, you should add System.Web and System.Web.Services as reference, pick right click your solution and choose “Add reference” in your solution explorer, and search in .NET tabs.
This is the code example :
Dim proxy As New Net.WebProxy("http://proxy:80/", True) ' the proxy address
proxy.Credentials = New Net.NetworkCredential("username", "password", "domain") 'the credentials if any
Dim conv As New webservicex.CurrencyConvertor
conv.Proxy = proxy
result = conv.ConversionRate(webservicex.Currency.XAU, webservicex.Currency.IDR)
Catch exception ex
' Your error handling code
The result of that webservice is the current price of 1 troy ounce of gold in rupiah.
Simple enough huh?
Bang Jak as senior advisor😀 , http://www.webservicex.net, and the one and only, google, and vb.net forum on the web.
I’m not expert at this, a learner – traveler, much like you, the only difference is I knew this earlier than you (or you knew this earlier than me, and try to test me), and I try to return the favor by sharing it. So answer to your question would be something like, “Go google yourself”, or “I’ll try to look in to it” and you can have the answer in one or two month, if you’re lucky. Especially if you ask, how to create web services, because I haven’t learn it. But I’m open typo or editorial critics to improve my writting.