NCBI Bookshelf. A service of the National Library of Medicine, National Institutes of Health.

Entrez Programming Utilities Help [Internet]. Bethesda (MD): National Center for Biotechnology Information (US); 2010-.

Bookshelf ID: NBK55695

Using Entrez Utilities Web Service with Visual Basic and MS Visual Studio 2008

Last Update: November 10, 2010.

Entrez Utilities Web Service has been tested with:

  • Microsoft .NET Framework Version 3.5 SP1

  • Microsoft Visual Studio 2008 Version 9.0.30729.1 SP

Creating a Web Service Client Project

The following walkthrough describes how to create a Visual Basic project to access the NCBI Entrez Utilities Web Service using MS Visual Studio 2005.

To create Windows application:

1.

Press Ctrl+Shift+N or Select File menu, then New, and then click Project to open the New Project dialog.

2.

Select Visual C# in Project types list.

3.

Select Windows Forms Application in Templates list.

4.

Click OK to create a new project.

5.

Select View menu and then Toolbox to open a Toolbox window.

6.

From the Toolbox, drag a Textbox and a Button to the design surface of Form1. Set Textbox’ Multiline property to true.

7.

On the Project menu, click Add Service Reference.

8.

In the Address field of the Add Service Reference dialog, type the URL http://eutils.ncbi.nlm.nih.gov/soap/v2.0/eutils.wsdl or path to local file (for example, C:\SOAP\eUtils\v2.0\eutils.wsdl) if you downloaded eUtils WSDL/XSD files from our FTP site

9.

Click the Go button to retrieve information about the XML Web service.

10.

In the Namespace field type eUtils.

11.

Click OK. The new eUtils item will appear in Service References list in the Solution Explorer view.

12.

Double-click the button on Form1 to create an event-handling method for this button.

13.

In the Button1_Click method enter the following code:

' eInfo utility returns a list of available databases
Try
Dim serv As New eUtils.eUtilsServiceSoapClient
Dim req As New eUtils.eInfoRequest
Dim res As eUtils.eInfoResult
' call NCBI EInfo utility
res = serv.run_eInfo(req)
TextBox1.Text = ""
Dim i As Integer
For i = 0 To res.DbList.Items.Length – 1
TextBox1.Text += res.DbList.Items(i) + Chr(13) + Chr(10)
Next i

Catch eee As Exception
TextBox1.Text = eee.ToString()
End Try

14.

Build and run application.

Important: Currently, the default maximum length of the SOAP message is only 64Kb. C# application fails when Web Service response size exceeds this value. To increase the limit open app.config file located in the application’s root directory and change all maxReceivedMessageSize and maxBufferSize parameters to the same larger value, for example, 2000000.

NCBI Entrez Utilities Web Service API

Below is a list of available methods.

Click on parameter to get its description.

Click on method name to see the example of use.

Public Function run_eGquery( ByVal eGqueryRequest As eGQueryRequest) As Result

eGqueryRequest class properties:

Public Function run_eInfo(ByVal eInfoRequest As eInfoRequest) As eInfoResult

eInfoRequest class properties:

Public Function run_eLink(ByVal eLinkRequest As eLinkRequest) As eLinkResult

eLinkRequest class properties:

Public Function run_ePost(ByVal ePostRequest As ePostRequest) As ePostResult

ePostRequest class properties:

Public Function run_eSearch(ByVal eSearchRequest As eSearchRequest) As SearchResult

eSearchRequest class properties:

Public Function run_eSpell(ByVal eSpellRequest As eSpellRequest) As eSpellResult

eSpellRequest class properties:

Public Function run_eSummary(ByVal eSummaryRequest As eSummaryRequest) As SummaryResult

eSummaryRequest class properties:

Public Function run_eFetch(ByVal eFetchRequest As eFetchRequest) As eFetchResult

eFetchRequest class properties:

Properties available for Sequence databases:

Examples

Call EGQuery

    ' search in multiple Entrez databases
    Try
      Dim serv As New eUtils.eUtilsServiceSoapClient
      Dim req As New eUtils.eGqueryRequest
      Dim res As eUtils.Result
      ' call NCBI EGQuery utility
      req.term = "mouse"
      res = serv.run_eGquery(req)
      ' results output
      TextBox1.Text = "Search term: " + res.Term + Chr(13) + Chr(10)
      TextBox1.Text += "Results: " + Chr(13) + Chr(10)
      Dim i As Integer
      For i = 0 To res.eGQueryResult.ResultItem.Length - 1
        TextBox1.Text += "  " + res.eGQueryResult.ResultItem(i).DbName + _
                         ": " + res.eGQueryResult.ResultItem(i).Count + Chr(13) + Chr(10)
      Next i
    Catch eee As Exception
      TextBox1.Text = eee.ToString()
    End Try

Call EInfo

    ' eInfo utility returns an PMC db info
    Try
      Dim serv As New eUtils.eUtilsServiceSoapClient
      Dim req As New eUtils.eInfoRequest
      Dim res As eUtils.eInfoResult
      ' call NCBI EInfo utility
      req.db = "pmc"
      res = serv.run_eInfo(req)
      TextBox1.Text = ""
      TextBox1.Text += "DbName: " + res.DbInfo.DbName + Chr(13) + Chr(10)
      TextBox1.Text += "Description: " + res.DbInfo.Description + Chr(13) + Chr(10)
      TextBox1.Text += "MenuName: " + res.DbInfo.MenuName + Chr(13) + Chr(10)
    Catch eee As Exception
      TextBox1.Text = eee.ToString()
    End Try

Call EPost

    ' put Id list to history for later use
    Try
      Dim serv As New eUtils.eUtilsServiceSoapClient
      Dim req As New eUtils.ePostRequest
      Dim res As New eUtils.ePostResult
      ' call NCBI EPost utility
      req.db = "pubmed"
      req.id = "123,456,37281,983621"
      res = serv.run_ePost(req)
      ' results output
      TextBox1.Text = "WebEnv: " + res.WebEnv + Chr(13) + Chr(10) + "QueryKey: " + res.QueryKey
    Catch eee As Exception
      TextBox1.Text = eee.ToString()
    End Try

Call ESearch

    ' search in PubMed Central for stem cells in free fulltext articles
    Try
      Dim serv As New eUtils.eUtilsServiceSoapClient
      Dim req As New eUtils.eSearchRequest
      Dim res As eUtils.eSearchResult
      ' call NCBI ESearch utility
      ' NOTE: search term should be URL encoded
      req.db = "pmc"
      req.term = "stem+cells+AND+free+fulltext[filter]"
      req.RetStart = 0
      req.RetMax = 15
      res = serv.run_eSearch(req)
      ' results output
      TextBox1.Text = "Original query: stem cells AND free fulltext[filter]" + Chr(13) + Chr(10)
      TextBox1.Text += "Found ids: " + res.Count + Chr(13) + Chr(10)
      TextBox1.Text += "First " + res.RetMax + " ids: "
      Dim i As Integer
      For i = 0 To res.IdList.Length - 1
        TextBox1.Text += res.IdList(i) + " "
      Next i
    Catch eee As Exception
      TextBox1.Text = eee.ToString()
    End Try

Call ESpell

    ' retrieves spelling suggestions
     Try
       Dim serv As New eUtils.eUtilsServiceSoapClient
       Dim req As New eUtils.eSpellRequest
       Dim res As eUtils.eSpellResult
       ' call NCBI ESpell utility
       req.db = "pubmed"
       req.term = "mouss"
       res = serv.run_eSpell(req)
       ' results output
       TextBox1.Text = "Misspelled word: " + res.Query + Chr(13) + Chr(10)
       TextBox1.Text += "Corrected word: " + res.CorrectedQuery
     Catch eee As Exception
       TextBox1.Text = eee.ToString()
     End Try

Call ESummary

    ' retrieves document Summaries for ID list
    Try
      Dim serv As New eUtils.eUtilsServiceSoapClient
      Dim req As New eUtils.eSummaryRequest
      Dim res As eUtils.eSummaryResult
      ' call NCBI ESummary utility
      req.db = "nuccore"
      req.id = "28864546,28800981"
      res = serv.run_eSummary(req)
      ' results output
      TextBox1.Text = ""
      Dim i As Integer
      For i = 0 To res.DocSum.Length - 1
        TextBox1.Text += "ID: " + res.DocSum(i).Id + Chr(13) + Chr(10)
        Dim k As Integer
        For k = 0 To res.DocSum(i).Item.Length - 1
          If Not res.DocSum(i).Item(k).ItemContent Is Nothing Then
            TextBox1.Text += "  " + res.DocSum(i).Item(k).Name + _
                             ": " + res.DocSum(i).Item(k).ItemContent + Chr(13) + Chr(10)
          End If
        Next k
        TextBox1.Text += "-----------------------" + Chr(13) + Chr(10) + Chr(13) + Chr(10)
      Next i
    Catch eee As Exception
      TextBox1.Text = eee.ToString()
    End Try

Call EFetch

To fetch data from one of the supported databases add the corresponding Web Reference to project. For example, for taxonomy database in Add Service Reference dialog type http://eutils.ncbi.nlm.nih.gov/soap/v2.0/efetch_taxon.wsdl in Address field and eFetchTaxon in Namespace.

Taxonomy database example:

    ' fetch a record from Taxonomy database
    Try
      Dim serv As New eFetchTaxon.eUtilsServiceSoapClient
      Dim req As New eFetchTaxon.eFetchRequest
      Dim res As eFetchTaxon.eFetchResult
      ' call NCBI EFetch utility
      req.id = "9685"
      res = serv.run_eFetch(req)
      ' results output
      TextBox1.Text = res.TaxaSet(0).ScientificName + ": " + _
                      res.TaxaSet(0).Division + " (" + _
                      res.TaxaSet(0).Rank + ")" + Chr(10)
    Catch eee As Exception
      TextBox1.Text = eee.ToString()
    End Try

Using WebEnv & QueryKey example

Add two Service References to the project: http://eutils.ncbi.nlm.nih.gov/soap/v2.0/eutils.wsdl and http://eutils.ncbi.nlm.nih.gov/soap/v2.0/efetch_pubmed.wsdl files.

Name them eUtils and eFetchPubmed correspondingly.

Important: Increase all maxReceivedMessageSize and maxBufferSize parameters in app.config file to 2000000 before running the application.

        Dim WebEnv As String
        Dim query_key As String
        WebEnv = ""
        query_key = ""


        ' STEP #1: search in PubMed for "cat"
        '
        Try
            Dim serv As New eUtils.eUtilsServiceSoapClient
            Dim req As New eUtils.eSearchRequest
            Dim res As eUtils.eSearchResult
            ' call NCBI ESearch utility
            ' NOTE: search term should be URL encoded
            req.db = "pubmed"
            req.usehistory = "y"
            req.term = "cat"
            res = serv.run_eSearch(req)
            ' store WebEnv & QueryKey for use in eFetch
            WebEnv = res.WebEnv
            query_key = res.QueryKey


            TextBox1.Text = "Search in PubMed for cat returned " + res.Count + " hits" + Chr(13) + Chr(10)
            TextBox1.Text += "WebEnv: " + WebEnv + Chr(13) + Chr(10)
            TextBox1.Text += "QueryKey: " + query_key + Chr(13) + Chr(10) + Chr(13) + Chr(10)


        Catch eee As Exception
            TextBox1.Text += eee.ToString()
        End Try


        'STEP #2: fetch 5 records from pubmed starting from record #10
        Try
            Dim serv As New eFetchPubmed.eUtilsServiceSoapClient
            Dim req As New eFetchPubmed.eFetchRequest
            Dim res As eFetchPubmed.eFetchResult
            ' call NCBI EFetch utility
            req.WebEnv = WebEnv
            req.query_key = query_key
            req.retstart = 10
            req.retmax = 5
            res = serv.run_eFetch(req)
            ' results output
            ' PubmedArticleSet array can include articles of PubmedArticleType and
            ' PubmedBookArticleType types. There should be separate display method
            ' for each article's type.
            Dim i As Integer
            For i = 0 To res.PubmedArticleSet.Length - 1
                Dim art As eFetchPubmed.PubmedArticleType
                Dim book As eFetchPubmed.PubmedBookArticleType
                art = Nothing
                book = Nothing
                If TypeOf (res.PubmedArticleSet(i)) Is eFetchPubmed.PubmedArticleType Then
                    art = res.PubmedArticleSet(i)
                Else
                    book = res.PubmedArticleSet(i)
                End If


                If Not art Is Nothing Then
                    TextBox1.Text += "Type: Pubmed Article" + Chr(13) + Chr(10)
                    TextBox1.Text += "Title: " + art.MedlineCitation.Article.ArticleTitle.Value + Chr(13) + Chr(10)
                    TextBox1.Text += "--------------------------" + Chr(13) + Chr(10) + Chr(13) + Chr(10)
                End If
                If Not book Is Nothing Then
                    TextBox1.Text += "Type: Pubmed Book Article" + Chr(13) + Chr(10)
                    TextBox1.Text += "Title: " + book.BookDocument.ArticleTitle.Value + Chr(13) + Chr(10)
                    TextBox1.Text += "--------------------------" + Chr(13) + Chr(10) + Chr(13) + Chr(10)
                End If


            Next i


        Catch eee As Exception
            TextBox1.Text = eee.ToString()
        End Try

Copyright Notice: http://www.ncbi.nlm.nih.gov/books/about/copyright/

Cover of Entrez Programming Utilities Help
Entrez Programming Utilities Help [Internet].

Recent activity

Your browsing activity is empty.

Activity recording is turned off.

Turn recording back on

See more...