I own literally thousands of books, both paper and electronic. So many, in fact, that it can be tough to remember if I own a particular title.

So I started playing with the idea of writing a personal library manager (Using WPF and C#)

Service Oriented Application Design has been around for a long time and I’ve been working with “Web Services” for more than a decade. Microsoft made web services use easy with the introduction of the first version of .NET, but the web services mechanism in ASP.NET is primarily wired for SOAP / WSDL. That’s fine and those technologies work great, but SOAP is overkill for many (most) of the RCP style service method calls that so many application need to make.

In recent years there has been a migration to AJAX services that return JSON (JavaScript Object Notation), but sometimes XML is the better choice.

POX = Plain Old XML

So in my playing with ideas for a personal library manager I found ISBNDB.com which has both free and paid accounts that let you search the entire ISBN Database via a URL endpoint.

But, it does NOT support SOAP/WSDL.

You use the service by making an HTTP request to a parameterized URL like this:

http://isbndb.com/api/books.xml?access_key=XXXXXXXX&index1=isbn&value1=9999999999

Where  XXXXXXXX is an access key provided when you register for an account and where 9999999999 is an ISBN number.

The service returns POX (Plain Old XML) as in the folloing actual response from the server.


<ISBNdb server_time='2011-08-01T23:00:52Z'>
    <BookList total_results='1' page_size='10' page_number='1'
	                                          shown_results='1'>
        <BookData book_id='101_secrets_of_highly_effective_speakers_3rd_ed'
                           isbn='1570232296' isbn13='9781570232299'>
            <Title>
                101 Secrets of Highly Effective Speakers, 3rd Edition
            </Title>
            <TitleLong>
                101 Secrets of Highly Effective Speakers, 3rd Edition:
                Controlling Fear, Commanding Attention
            </TitleLong>
            <AuthorsText>Caryl R Krannich,</AuthorsText>
            <PublisherText publisher_id='impact_publications'>
                Impact Publications
            </PublisherText>
        </BookData>
    </BookList>
</ISBNdb>

Note that I’ve formated the XML for displpay purposes.


So, I threw together a quick WPF form :

… and wired up a button click event hanlder ….


private void btnGo_Click(object sender, RoutedEventArgs e)
{
    StringBuilder sb = new StringBuilder();
    byte[] buf = new byte[8192];
    HttpWebRequest request = (HttpWebRequest)
        WebRequest.Create('http://isbndb.com/api/books.xml?
                           access_key=TEQSZTNO&amp;index1=isbn&amp;value1=' +
						   ISBN_In.Text);

    HttpWebResponse response = (HttpWebResponse) request.GetResponse();
    Stream resStream = response.GetResponseStream();

    string XMLResultString = null;
    int count = 0;
    do
    {
        // fill the buffer with data
        count = resStream.Read(buf, 0, buf.Length);
        // make sure we read some data
        if (count != 0)
        {
            // translate from bytes to ASCII text
            XMLResultString = Encoding.ASCII.GetString(buf, 0, count);
            // continue building the string
            sb.Append(XMLResultString);
        }
    }
    while (count &gt; 0);

    XmlDocument ISBN_XML =  new XmlDocument();
    ISBN_XML.LoadXml(XMLResultString);

    tb1.Text = '';
    if (ISBN_XML.GetElementsByTagName('BookList').Item(0)
                .Attributes.GetNamedItem('total_results').Value == '0')
    {
        tb1.Inlines.Add('ERROR : No result found for specified ISBN Number.');
    }
    else
    {
        tb1.Inlines.Add('TITLE : ' +
            ISBN_XML.GetElementsByTagName('Title').Item(0).InnerText);
        tb1.Inlines.Add(new LineBreak());
        tb1.Inlines.Add('FULL TITLE : ' +
            ISBN_XML.GetElementsByTagName('TitleLong').Item(0).InnerText);
        tb1.Inlines.Add(new LineBreak());
        tb1.Inlines.Add('AUTHOR : ' +
            ISBN_XML.GetElementsByTagName('AuthorsText').Item(0).InnerText);
        tb1.Inlines.Add(new LineBreak());
        tb1.Inlines.Add('PUBLISHER : ' +
            ISBN_XML.GetElementsByTagName('PublisherText').Item(0).InnerText);
    }

}

When I enter a vaild ISBN Number (like the one I coded as a default) the UI displays the results of the Web Service.

Take special note of the if statement at line 33 in the listing above.

The web service call can return valid XML but no result record (the ISBN number was not found). We need to examine the XML to make user that the query result includes an ISBN record. Otherwise our first call to GetElementsByTagName for the Title will throw an exception becuase it returns a null.

You can download the working sample [ HERE ]

You will have to go to ISBNDB.com and set up your own account and then edit the button click event handler by inserting your own access key.

Have fun !