Hello everyone. I am a student and I am developing an application in c# with visual studio 2010 that returns a few articles related to a given term like "anemia". The problem is : in the code that I found in the NCBI website it works fine, returns the expected (5 items). I tryed to increase this number to 20 but only returns 12 because it launches an NULL exception before that.
The items returned should be correct right? Why exist null exceptions in the middle of list?
Could anyone help how to fix this?
Best regards, Costa
the code:
String data = null;
String WebEnv = "";
String query_key = "";
// STEP #1: search in PubMed for "cat"
//
try
{
eUtils.eUtilsServiceSoapClient serv = new eUtils.eUtilsServiceSoapClient();
// call NCBI ESearch utility
// NOTE: search term should be URL encoded
eUtils.eSearchRequest req = new eUtils.eSearchRequest();
req.db = "pubmed";
req.term = "cat";
req.usehistory = "y";
eUtils.eSearchResult res = serv.run_eSearch(req);
// store WebEnv & QueryKey for use in eFetch
WebEnv = res.WebEnv;
query_key = res.QueryKey;
data = "Search in PubMed for \"cat\" returned " + res.Count + " hits\r\n";
data += "WebEnv: " + WebEnv + "\r\n";
data += "QueryKey: " + query_key + "\r\n\r\n";
}
catch (Exception eee)
{
data += eee.ToString();
}
// STEP #2: fetch 5 records from pubmed starting from record #10
//
try
{
eFetchPubmed.eUtilsServiceSoapClient serv = new eFetchPubmed.eUtilsServiceSoapClient();
// call NCBI EFetch utility
eFetchPubmed.eFetchRequest req = new eFetchPubmed.eFetchRequest();
req.WebEnv = WebEnv;
req.query_key = query_key;
req.retstart = "0";
req.retmax = "20";
eFetchPubmed.eFetchResult 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.
for (int i = 0; i < res.PubmedArticleSet.Length; i++)
{
eFetchPubmed.PubmedArticleType art = null;
eFetchPubmed.PubmedBookArticleType book = null;
if (res.PubmedArticleSet[i] is eFetchPubmed.PubmedArticleType)
art = (eFetchPubmed.PubmedArticleType)res.PubmedArticleSet[i];
else
book = (eFetchPubmed.PubmedBookArticleType)res.PubmedArticleSet[i];
// show book or article
if (art != null)
{
data += "Type: Pubmed Article\r\n";
data += "Title: " + art.MedlineCitation.Article.ArticleTitle + "\r\n";
data += "Abstract: " + art.MedlineCitation.Article.Abstract.AbstractText + "\r\n";
data += "--------------------------\r\n\r\n";
count++;
}
else if (book != null)
{
data += "Type: Pubmed Book Article\r\n";
data += "Title: " + book.BookDocument.ArticleTitle + "\r\n";
data += "--------------------------\r\n\r\n";
}
}
}
catch (Exception eee)
{
data += eee.ToString();
}
System.Diagnostics.Debug.Write(data);
Please post the full stacktrace. And are you using the code exactly as shown here (are you searching for cat?) My first guess would have been that there were only 12 results, but cat gives more. Can't say more without a stacktrace though.
Hy!I have a problem with code that i found from NCBI website.I want to display an article and abstract in a textbox. The code is this: String WebEnv = "";
And the error is this: Type: Pubmed Article Title: WindowsFormsApplication1.eFetchPubmed.ArticleTitleType Abstract: WindowsFormsApplication1.eFetchPubmed.AbstractTextType[]
Can you help me? Thank you!