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.

screenshot untuk add web reference

screenshot untuk add web reference

screenshot layar wizard

screenshot layar wizard

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.

Screenshot Add Reference

Screenshot Add Reference

This is the code example :

Try
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
End Try

The result of that webservice is the current price of 1 troy ounce of gold in rupiah.

Simple enough huh?

Reference :
Bang Jak as senior advisor :D , http://www.webservicex.net, and the one and only, google, and vb.net forum on the web.

Disclaimer :

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.

Thank you.

7 Tanggapan

  1. Komentar oleh dnial on 23 Juli, 2008 8:31 am

    Rulers should serve the state so that their children will dream of being its servants.
    - Leonid S. Sukhorukov -

  2. Komentar oleh galih on 23 Juli, 2008 8:50 am

    Screenshot dude? tanpa skrinsyut adalah basbang…

  3. Komentar oleh dnial on 23 Juli, 2008 8:53 am

    Ah… silly me…
    I’ll try to look in to it. :P

  4. Komentar oleh EL on 23 Juli, 2008 6:32 pm

    daniel saiki ndotNETan pek…

    ngeriiiiiiiiiiiiiii………

  5. Komentar oleh dnial on 24 Juli, 2008 7:07 am

    @El
    Tuntutan profesi, man. :P
    Lagian dotnet sebenernya nggak susah2 amat.

  6. Komentar oleh Ace on 24 Juli, 2008 5:20 pm

    nice…

  7. Komentar oleh dr on 26 Juli, 2008 2:00 am

    yang C# mana? :P
    kantormu berarti ga nerima orderan C# ya?

Komentar RSS Lacak Balik URI Pengenal

Tinggalkan komentar