Entrez PubMed Nucleotide Protein Genome Structure OMIM PMC Journals Books

Using E-Utilities Web Service with C# in MS Visual Studio .NET
Updated: January 12, 2006

SOAP Interface for E-Utilities was tested with:
  - Microsoft Windows XP Professional Version 2002 (Service Pack2)
  - Microsoft .NET Framework 1.1 Version 1.1.4322
  - Microsoft Development Environment 2003 Version 7.1.3088

Note: Microsoft .NET Framework 1.0 does not work with eutils. You should update it to version 1.1 at least.

Creating an NCBI Web Service Client Project

The following walkthrough describes the process for accessing the NCBI E-Utilities Web service from an application created with Visual C#.

To create Windows application:

SOAP E-Utilities API

Below is a list of methods we recommend for use with C#.
SOAP interface provides user with two functionally identical sets of methods.
Methods which name ends with _MS are designed for use with Microsoft Visual Studio and SOAP Toolkit 3.0

Click on parameter to get its description.
Click on method name to see the example of use.

  1. public GQueryResultType run_eGquery_MS( string term, string tool, string email );
  2. public eInfoResultType run_eInfo_MS( string db, string tool, string email );
  3. public eLinkResultType run_eLink_MS( 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 );
  4. public eSearchResultType run_eSearch_MS( 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 );
  5. public eSpellResultType run_eSpell_MS( string db, string term, string tool, string email );
  6. public eSummaryResultType run_eSummary_MS( string db, string id, string WebEnv, string query_key, string retstart, string retmax, string tool, string email );
  7. public eFetchResultType run_eFetch_MS( string db, string id, string WebEnv, string query_key, string tool, string email, string retstart, string retmax, string rettype, // *rettype for Molecular Biology Databases string strand, string seq_start, string seq_stop, string complexity, string report );

Examples

Call EGQuery

// run_eGquery_MS provides Entrez database counts for a single search 
try
{
    eUtils.eUtilsService serv = new eUtils.eUtilsService();
    // call NCBI EGQuery utility
    eUtils.GQueryResultType res = serv.run_eGquery_MS("mouse", "", "");
    // results output
    label1.Text = "Search term: " + res.Term + "\n";
    label1.Text += "Results: \n";
    for(int i=0; i<res.eGQueryResult.ResultItem.Length; i++) 
    {
        label1.Text += "  " + res.eGQueryResult.ResultItem[i].DbName + 
                       ": " + res.eGQueryResult.ResultItem[i].Count + "\n";
    }
}
catch
{
    label1.Text = "Failed";
}


Call EInfo

   // eInfo utility returns a list of available databases
   try
   {
        eUtils.eUtilsService serv = new eUtils.eUtilsService();
        // call NCBI EInfo utility
        eUtils.eInfoResultType res = serv.run_eInfo_MS("", "", "");
        // results output
        label1.Text = "";			
        for(int i=0; i<res.DbList.Items.Length; i++) label1.Text += res.DbList.Items[i]+"\n";
   }
   catch
   {
        label1.Text = "Failed";
   }


Call ELink

// example retrieves IDs from Nucleotide for GI 48819,7140345 to Protein
try
{
    eUtils.eUtilsService serv = new eUtils.eUtilsService();
    string[] id = {"48819,7140345"};
    // call NCBI ELink utility
    eUtils.eLinkResultType res = serv.run_eLink_MS("protein", id, "", "", "", "", "", 
                                                   "nucleotide", "", "", "", "", "");
    // results output
    label1.Text = "";
    for(int i=0; i<res.LinkSet.Length; i++)
    {
        label1.Text += "Links from " + res.LinkSet[i].DbFrom + " to " + res.LinkSet[i].LinkSetDb[0].DbTo + "\n";
        label1.Text += "  " + res.LinkSet[i].DbFrom + " id(s): ";
        for(int k=0; k<res.LinkSet[i].IdList.Length; k++) 
        {
            label1.Text +=  res.LinkSet[i].IdList[k].Value + " ";
        }
        label1.Text += "\n";
        label1.Text += "  " + res.LinkSet[i].LinkSetDb[0].DbTo + " id(s): ";
        for(int k=0; k<res.LinkSet[i].LinkSetDb[0].Items.Length; k++) 
        {
            eUtils.LinkType1 lt = (eUtils.LinkType1)res.LinkSet[i].LinkSetDb[0].Items[k];
            label1.Text +=  lt.Id.Value + " ";
        }
        label1.Text += "\n----------------------\n";
    }
}
catch
{
    label1.Text = "Failed";
}		


Call ESearch

// search in PubMed Central for stem cells in free fulltext articles
try
{
    eUtils.eUtilsService serv = new eUtils.eUtilsService();
    // call NCBI ESearch utility
    // NOTE: search term should be URL encoded 
    eUtils.eSearchResultType res = serv.run_eSearch_MS("pmc", "stem+cells+AND+free+fulltext[filter]", 
                                                       "", "", "", "", "", "", "", "", "", "", "0", 
                                                       "15", "", "");
    // results output
    label1.Text = "Original query: stem cells AND free fulltext[filter]\n";
    label1.Text += "Found ids: " + res.Count+"\n";
    label1.Text += "First " + res.RetMax +" ids: ";

    for(int i=0; i<res.IdList.Length; i++)
    {
        label1.Text += res.IdList[i] + " ";
    }
}
catch
{
    label1.Text = "Failed";
}		


Call ESpell
			
// retrieves spelling suggestions
try
{
    eUtils.eUtilsService serv = new eUtils.eUtilsService();
    // call NCBI ESpell utility
    eUtils.eSpellResultType res = serv.run_eSpell_MS("pubmed", "mouss", "", "");
    // results output
    label1.Text = "Misspelled word: "+res.Query + "\n";
    label1.Text += "Corrected word: "+res.CorrectedQuery;
}
catch
{
    label1.Text = "Failed";
}		


Call ESummary
			
// retreives document Summaries by list of primary IDs
try
{
    eUtils.eUtilsService serv = new eUtils.eUtilsService();
    // call NCBI ESummary utility
    eUtils.eSummaryResultType res = serv.run_eSummary_MS("nucleotide", "28864546,28800981", 
                                                         "", "", "", "", "", "");
    // results output
    label1.Text = "";
    for(int i=0; i<res.DocSum.Length; i++)
    {
        label1.Text += "ID: "+res.DocSum[i].Id+"\n";
        for(int k=0; k<res.DocSum[i].Item.Length; k++)
        {
	  if(res.DocSum[i].Item[k].Text!=null)
            label1.Text += "    "+res.DocSum[i].Item[k].Name +": "+res.DocSum[i].Item[k].Text[0]+"\n";
        }
        label1.Text += "-----------------------\n\n";
    }
}
catch
{
    label1.Text = "Failed";
}		


Call EFetch
Literature database example

// fetch article from pubmed and displays its abstract
try
{
    eUtils.eUtilsService serv = new eUtils.eUtilsService();
    // call NCBI EFetch utility
    eUtils.eFetchResultType res = serv.run_eFetch_MS("pubmed", "11748933,11700088", "", "", 
                                                     "", "", "", "", "", "", "", "", "", "");
    // results output
    label1.Text = "";
    for(int i=0; i<res.PubmedArticleSet.Length; i++)
    {
        label1.Text += "ID: "+res.PubmedArticleSet[i].MedlineCitation.PMID + "\n";
        label1.Text += "Abstract: "+res.PubmedArticleSet[i].MedlineCitation.Article.Abstract.AbstractText + "\n";
        label1.Text += "--------------------------\n\n";
    }
}
catch
{
    label1.Text = "Failed";
}		

Taxonomy database example

// fetch a record from Taxonomy database
try
{
    eUtils.eUtilsService serv = new eUtils.eUtilsService();
    // call NCBI EFetch utility
    eUtils.eFetchResultType res = serv.run_eFetch_MS("taxonomy", "9685", "", "", "", 
                                                     "", "", "", "", "", "", "", "", "");
    // results output
    label1.Text =   res.TaxaSet[0].ScientificName + ": " + 
                    res.TaxaSet[0].Division + " (" + 
                    res.TaxaSet[0].Rank + ")\n";
}
catch
{
    label1.Text = "Failed";
}		

<< Back

 

 Write to the Help Desk
NCBI | NLM | NIH
Department of Health & Human Services
Privacy Statement | Freedom of Information Act | Disclaimer