[
Back]
Calling the RAS webservice from Visual Basic .NET 2010
This tutorial assumes you have installed Micosoft Visual Basic .NET 2010.
Step 1: Start a new Windows Forms Application project
Name it 'RASReferenceExample'
Then click Project from the top Menu
Select Add Service Reference...
In the Address box add 'https://ras.biodiversity.aq/aphia.php?p=soap&wsdl=1', then click Go
The AphiaNameService should appear and if you expand the list you will see 'AphiaNameServicePortType'
Step 2: make a button
In the Namespace box select a suitable name
Add a button to your project from the Toolbox and name it btnQueryTaxa
Add a list box from the Toolbox add it to your form and name it lstRecords
Double click on the button to access its click event
Adjust your projects Form code to look like the following code
Imports RASReferenceExample.RASReference
Public Class Form1
Private Sub btnQueryTaxa_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnQueryTaxa.Click
'Declare dimensions
Dim i As Integer, objRASTool As New AphiaNameServicePortTypeClient, objRecords() As AphiaRecord, strUserInput As String
'Get users input of a string
strUserInput = Trim(InputBox("Please enter a taxa to Query", "RAS Query"))
'Use the users input to get the possible records from the RAS website
objRecords = objRASTool.getAphiaRecords(strUserInput, True, True, True, 1)
'clear the listbox prior to filling it
lstRecords.Items.Clear()
'loop through retrieved records and
For i = 0 To objRecords.GetUpperBound(0)
lstRecords.Items.Add(objRecords(i).scientificname)
Next
'inform the user that the query is complete
MsgBox("Query Completed Successfully with " & objRecords.GetUpperBound(0) + 1 & "Records Retrieved", MsgBoxStyle.OkOnly, "RAS Query")
End Sub
End Class
Note if your project will be connecting to the internet via a proxy server please add the following lines of code to the app.config file after the
section
<system.net>
<settings>
<servicePointManager expect100Continue="false"/>
</settings>
<defaultProxy useDefaultCredentials="true"></defaultProxy>
</system.net>
Download this example.
Download an example without having to rely on the settings in the App.Config file
Credits for this tutorial go to Michael Thompson (Gardline Environmental, UK) & Jeroen Steenbeek (University of British Columbia, Canada)