RAMS logo
Introduction | Species lists | Search taxa | Taxon tree | Literature | Distributions | Statistics | Editors | Match taxa | Webservice | Log in
[Back]

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


Website and databases developed and hosted by VLIZ · Page generated 2024-03-28 GMT · contact: Anton Van de Putte