WoRMS banner
Add search provider Add provider
Twitter: Latest updates @WRMarineSpecies
[Back]

Calling the WoRMS 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 'WoRMSReferenceExample'
Then click Project from the top Menu
Select Add Service Reference...
In the Address box add 'http://www.marinespecies.org/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 WoRMSReferenceExample.WoRMSReference
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, objWoRMSTool As New AphiaNameServicePortTypeClient, objRecords() As AphiaRecord, strUserInput As String
        'Get users input of a string
        strUserInput = Trim(InputBox("Please enter a taxa to Query", "WoRMS Query"))
        'Use the users input to get the possible records from the WoRMS website
        objRecords = objWoRMSTool.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, "WoRMS 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)