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-.
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:
-
String db
-
String[] id
-
String reldate
-
String mindate
-
String maxdate
-
String datetype
-
String term
-
String dbfrom
-
String WebEnv
-
String query_key
-
String cmd
-
String tool
-
String email
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:
-
String db
-
String term
-
String WebEnv
-
String query_key
-
String usehistory
-
String tool
-
String email
-
String field
-
String reldate
-
String mindate
-
String maxdate
-
String datetype
-
String retstart
-
String retmax
-
String rettype
-
String sort
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:
-
String db
-
String id
-
String WebEnv
-
String query_key
-
String retstart
-
String retmax
-
String tool
-
String email
Public Function run_eFetch(ByVal eFetchRequest As eFetchRequest) As eFetchResult
eFetchRequest class properties:
-
String db
-
String id
-
String WebEnv
-
String query_key
-
String tool
-
String email
-
String retstart
-
String retmax
-
String rettype
Properties available for Sequence databases:
-
String rettype
-
String strand
-
String seq_start
-
String seq_stop
-
String complexity
-
String report
Examples
Call ' 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 EGQuery
Call ' 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 EInfo
Call ' example retrieves links from Nucleotide to Protein for GI 48819,7140345 Try Dim serv As New eUtils.eUtilsServiceSoapClient Dim req As New eUtils.eLinkRequest Dim res As eUtils.eLinkResult Dim id(1) As String id(0) = "48819,7140345" ' call NCBI ELink utility req.db = "protein" req.dbfrom = "nuccore" req.id = id res = serv.run_eLink(req) ' results output TextBox1.Text = "" Dim i As Integer For i = 0 To res.LinkSet.Length - 1 TextBox1.Text += "Links from " + res.LinkSet(i).DbFrom + " to " + res.LinkSet(i).LinkSetDb(0).DbTo + Chr(13) + Chr(10) TextBox1.Text += " " + res.LinkSet(i).DbFrom + " id(s): " Dim k As Integer For k = 0 To res.LinkSet(i).IdList.Length - 1 TextBox1.Text += res.LinkSet(i).IdList(k).Value + " " Next k TextBox1.Text += Chr(13) + Chr(10) TextBox1.Text += " " + res.LinkSet(i).LinkSetDb(0).DbTo + " id(s): " For k = 0 To res.LinkSet(i).LinkSetDb(0).Link.Length - 1 TextBox1.Text += res.LinkSet(i).LinkSetDb(0).Link(k).Id.Value + " " Next k TextBox1.Text += Chr(13) + Chr(10) + "----------------------" + Chr(13) + Chr(10) Next i Catch eee As Exception TextBox1.Text = eee.ToString() End Try ELink
Call ' 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 EPost
Call ' 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 ESearch
Call ' 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 ESpell
Call ' 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 ESummary
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
Search, Link & Fetch 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_seq.wsdl files.
Name them eUtils and eFetchSeq correspondingly.
Important: Increase all maxReceivedMessageSize and maxBufferSize parameters in app.config file to 2000000 before running the application.
Dim ids(1) As String
Dim fetchIds As String
ids(0) = ""
fetchIds = ""
' 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.sort = "PublicationDate"
req.term = "cat+AND+pubmed_nuccore[sb]"
req.RetMax = "5"
res = serv.run_eSearch(req)
' store UIDs for use in ELink
Dim i As Integer
For i = 0 To res.IdList.Length - 1
If i > 0 Then
ids(0) += ","
End If
ids(0) += res.IdList(i)
Next i
TextBox1.Text = "Search in PubMed for cat returned " + res.Count + " hits" + Chr(13) + Chr(10)
TextBox1.Text += "Search links in nuccore for the first 5 UIDs: " + ids(0) + Chr(13) + Chr(10) + Chr(13) + Chr(10)
Catch eee As Exception
TextBox1.Text += eee.ToString()
End Try
' STEP #2: get links in nucleotide database (nuccore)
'
Try
Dim serv As New eUtils.eUtilsServiceSoapClient
Dim req As New eUtils.eLinkRequest
Dim res As eUtils.eLinkResult
' call NCBI ELink utility
req.dbfrom = "pubmed"
req.db = "nuccore"
req.id = ids
res = serv.run_eLink(req)
' read result and create a list of UIDs to fetch
Dim i As Integer
For i = 0 To res.LinkSet(0).LinkSetDb(0).Link.Length - 1
If i > 0 Then
fetchIds += ","
End If
fetchIds += res.LinkSet(0).LinkSetDb(0).Link(i).Id.Value
Next i
TextBox1.Text += "ELink returned the following UIDs from nuccore: " + fetchIds + Chr(13) + Chr(10) + Chr(13) + Chr(10)
Catch eee As Exception
TextBox1.Text += eee.ToString()
End Try
' STEP #3: fetch records from nuccore
'
Try
Dim serv As New eFetchSeq.eUtilsServiceSoapClient
Dim req As New eFetchSeq.eFetchRequest
Dim res As eFetchSeq.eFetchResult
' call NCBI EFetch utility
req.db = "nuccore"
req.id = fetchIds
res = serv.run_eFetch(req)
' results output
Dim i As Integer
For i = 0 To Math.Min(4, res.GBSet.GBSeq.Length - 1)
TextBox1.Text += "Organism: " + res.GBSet.GBSeq(i).GBSeq_organism + Chr(13) + Chr(10)
TextBox1.Text += "Locus: " + res.GBSet.GBSeq(i).GBSeq_locus + Chr(13) + Chr(10)
TextBox1.Text += "Definition: " + res.GBSet.GBSeq(i).GBSeq_definition + Chr(13) + Chr(10)
TextBox1.Text += "----------------------" + Chr(13) + Chr(10) + Chr(13) + Chr(10)
Next i
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
Download
- PDF version of this page (546K)
Other titles in this collection
Recent Activity
-
Using Entrez Utilities Web Service with Visual Basic and MS Visual Studio 2008 -...
Using Entrez Utilities Web Service with Visual Basic and MS Visual Studio 2008 - Entrez Programming Utilities HelpBookself
Your browsing activity is empty.
Activity recording is turned off.
Turn recording back on
See more...