spacer
spacer

Visual Basic .NET

Introduction

Visual Basic .NET is the most popular programming language on the .NET framework. For more details of the .NET platform and the development environments see our .NET tutorial.

Microsoft .NET SDK and Mono

Create Service Stubs

From the service WSDL (e.g. http://www.ebi.ac.uk/ws/services/WSDbfetch?wsdl) generate stub classes using the wsdl tool:

wsdl /l:VB "http://www.ebi.ac.uk/ws/services/WSDbfetch?wsdl"

Use Service

Then in the program create an instance of the service object:

Dim Dbfetch As WSDBFetchServerService = New WSDBFetchServerService()

This object provides methods corresponding to those defined in the WSDL so to call the fetchData method of the WSDbfetch service we can use:

Dim result As String
result = Me.Dbfetch.fetchData("UNIPROT:ADH1A_HUMAN", "default", "raw")

The fetchData method returns a string containing the requested database entry, which can be output with:

Console.Write(result)

Compile Program

Once the program has been completed, it needs to be compiled. Assuming the program is in a file called wsdbfetch.vb:

Microsoft .NET SDK

vbc wsdbfetch.vb WSDBFetchServerService.vb

Mono

vbnc wsdbfetch.vb WSDBFetchServerService.vb

See http://www.mono-project.com/VisualBasic.NET_support

Run the Program

The resulting .exe. file can be run as follows:

MS Windows, assuming the .NET runtime is installed:

wsdbfetch.exe

Non-Windows Mono environments:

mono wsdbfetch.exe

Note: some non-Windows environments (e.g. Linux) can be configured to support direct execution of .NET programs, allowing the use of the Windows style method.

Using Data Structures

The methods in the WSDbfetch service all use simple string parameters. Many of the other EBI services use more complex input structures. For example WSInterProScan requires a structure containing the various parameters and the input sequence to be passed to the runInterProScan method:

' The input parameters
Dim input As inputParams = New inputParams()
' Set the required parameters
input.email = "your@email"
input.async = True
input.seqtype = "p"
input.crc = true
' The input data
Dim content As data()
content = New data(0) {}
content(0) = New data()
' Input type
content(0).type = "seqeunce"
' Input data
content(0).content = ">Q8E5Q5_STRA3" & Environment.NewLine & _
"MKLSKRYRFWQKVIKALGVLALIATLVLVVYLYKLGILNDSNELKDLVHKYEFWGPMIFI" & Environment.NewLine & _
"VAQIVQIVFPVIPGGVTTVAGFLIFGPTLGFIYNYIGIIIGSVILFWLVKFYGRKFVLLF" & Environment.NewLine & _
"MDQKTFDKYESKLETSGYEKFFIFCMASPISPADIMVMITGLSNMSIKRFVTIIMITKPI" & Environment.NewLine & _
"SIIGYSYLWIYGGDILKNFLN"
' Submit the job
Dim InterProScan As WSInterProScanService = New WSInterProScanService()
Dim jobId As String = InterProScan.runInterProScan(input, content)
Console.WriteLine(jobId)

The runInterProScan method returns a job identifier which can be used with the checkStatus method to get the status of the job (e.g. RUNNING, DONE or ERROR) and the poll method to get the results of the job.

Dim status As String = "PENDING"
' Check status and wait if not finished
While status = "RUNNING" OrElse status = "PENDING"
  status = InterProScan.getStatus(jobId)
  Console.WriteLine(status)
  If status = "RUNNING" OrElse status = "PENDING" Then
    ' Wait before polling again.
    System.Threading.Thread.Sleep(15000)
  End If
End While
' Get results
Dim res As Byte() = InterProScan.poll(jobId, "toolraw")
' Convert result into a string for output
Dim enc As New System.Text.ASCIIEncoding()
Dim tempStr As String = enc.GetString(res)
' Output the result
Console.Write(tempStr)

Integrated Development Environment (IDE)

MonoDevelop

MonoDevelop: http://monodevelop.com/

To generate web service stubs (“Web Reference”) using MonoDevelop:

  1. Right-click on the project you want to add the stubs to, and select the “Add Web Reference” option.
  2. Paste the URL of the web service WSDL document into the “Web Service URL” text box.
  3. Click the “Jump to” button to load the service document and preview the service documentation and operations.
  4. Edit the name (“Reference”) of the “Web Reference” if required.
  5. Click “OK” to generate the stubs and add them to the project as a “Web Reference”.

For an example see: https://vtluug.org/wiki/MonoDevelop

SharpDevelop

SharpDevelop: http://sharpdevelop.net/OpenSource/SD/

To generate web service stubs (“Web Reference”) using SharpDevelop:

  1. Right-click on the project you want to add the stubs to, and select the “Add Web Reference” option.
  2. Paste the URL of the web service WSDL document into the text box.
  3. Click the “Go” button to load the service document and preview the service documentation and operations.
  4. Edit the name of the “Web Reference” if required.
  5. Edit the namespace of the “Web Reference” if required.
  6. Click “Add” to generate the stubs and add them to the project as a “Web Reference”.

For an example see: http://community.sharpdevelop.net/blogs/mattward/pages/AddingAndRemovingWebReferences.aspx

Visual Studio

Visual Studio 2005

To generate web service stubs (“Web Reference”) using Visual Studio 2005 (http://msdn.microsoft.com/en-us/library/d9w023sx(v=vs.80).aspx):

  1. Right-click on the project you want to add the stubs to, and select the “Add Web Reference” option.
  2. Paste the URL of the web service WSDL document into the “URL” text box.
  3. Click the “Go” button to load the service document and preview the service documentation and operations for the service(s) described by the document.
  4. Select the required service in the “Web services found at this URL” box.
  5. Edit the “Web reference name” if required.
  6. Click “Add Reference” to generate the stubs and add them to the project as a “Web Reference”.

Visual Studio 2008 & 2010

From Visual Studio 2008 onwards Windows Communication Foundation (WCF) based “Service Reference” are used by default. It is possible to generate a System.Web.Services style “Web Reference” for use with web services or applications that are incompatible with the “Service Reference”, for details see:

Sample Clients

Most SOAP Web Services at EMBL-EBI have sample clients which provide command-line access to the service and example code. For .NET some of the clients are implemented in Visual Basic .NET, for example:

Document/literal SOAP

RPC/encoded SOAP

Service Sample client
WSDbfetch (SOAP) .NET Executable: wsdbfetch.exe;
Source: wsdbfetch.vb
 
tutorials/06_programming/dot_net/vb.net.txt · Last modified: 2011/09/12 10:53 by hpm
spacer
spacer