Another Web Service offered at WebserviceX.net is a Bible Web Service. You can lookup verses, search by keyword and get the Book titles. I put together a script which gives you a pull-down menu of all the books in the Bible from which you can select chapter and verse.

In a WinForms form I need to collect the Bible Book, Chapter and Verse. Besides having to be spelled and formatted correctly, the query for Books requires your know the book name in advance. To assist in this I provide a list of the Books for selection in a ComboBox. I populate this list from a Web Services call, GetBookTitles.

Add-Type -AssemblyName System.Windows.Forms
# Main Form
$mainForm = New-Object System.Windows.Forms.Form
$mainForm.Font = "Comic Sans MS,10"
$mainForm.Text = " Bible Chapter Lookup (King James Version)"
$mainForm.ForeColor = "White"
$mainForm.BackColor = "DarkBlue"
$mainForm.Width = 800
$mainForm.Height = 600

# Book Input Label
$bookInputLabel = New-Object System.Windows.Forms.Label
$bookInputLabel.Location = "45,10"
$bookInputLabel.Height = 22
$bookInputLabel.Width = 100
$bookInputLabel.Text = "Book"
$mainForm.Controls.Add($bookInputLabel)

# Book Input ComboBox
$bookComboBox = New-Object System.Windows.Forms.ComboBox
$bookComboBox.Location = "145,10"
$bookComboBox.Size = "300,20"
$bookComboBox.ForeColor = "MediumBlue"
$bookComboBox.BackColor = "White"
# Add items to Combo box
$bibleBooks = New-WebServiceProxy -uri "http://www.webservicex.net/BibleWebservice.asmx?WSDL"
$books = [xml]$bibleBooks.GetBookTitles()
$bookList = $books.NewDataSet.Table | Select BookTitle
for ($i=0; $i -lt $bookList.Count; $i++) {
	[void]$bookComboBox.items.add($bookList.Item($i).BookTitle)
}
#$bookComboBox.SelectedIndex = 0;
$mainForm.Controls.Add($bookComboBox)

After the Book is selected I gather the required Chapter and Verse in TextBoxes.

# Chapter Input Label
$chapterInputLabel = New-Object System.Windows.Forms.Label
$chapterInputLabel.Location = "145,40"
$chapterInputLabel.Height = 22
$chapterInputLabel.Width = 70
$chapterInputLabel.Text = "Chapter"
$mainForm.Controls.Add($chapterInputLabel)

# Chapter Input TextBox
$chapterTextBox = New-Object System.Windows.Forms.TextBox
$chapterTextBox.Location = "220,40"
$chapterTextBox.Size = "50,20"
$chapterTextBox.ForeColor = "MediumBlue"
$chapterTextBox.BackColor = "White"
#$chapterTextBox.Text = "Enter Chapter"
$mainForm.Controls.Add($chapterTextBox)

# Verse Input Label
$verseInputLabel = New-Object System.Windows.Forms.Label
$verseInputLabel.Location = "335,40"
$verseInputLabel.Height = 22
$verseInputLabel.Width = 50
$verseInputLabel.Text = "Verse"
$mainForm.Controls.Add($verseInputLabel)

# Verse Input TextBox
$verseTextBox = New-Object System.Windows.Forms.TextBox
$verseTextBox.Location = "395,40"
$verseTextBox.Size = "50,20"
$verseTextBox.ForeColor = "MediumBlue"
$verseTextBox.BackColor = "White"
#$verseTextBox.Text = "Enter Verse"
$mainForm.Controls.Add($verseTextBox)

With a all the parameters gathered you can press the Lookup Button which calls the VerseLookup Function. This function makes a SOAP call, BibleVerse.GetBibleWordsByChapterAndVerse, to the WebserviceX Bible Web Service. The returned XML is processed for the Biblewords tag.

# Lookup Button
$lookupButton = New-Object System.Windows.Forms.Button
$lookupButton.Location = "470,10"
$lookupButton.Size = "75,28"
$lookupButton.ForeColor = "DarkBlue"
$lookupButton.BackColor = "White"
$lookupButton.Text = "Lookup"
$lookupButton.add_Click({VerseLookup})
$mainForm.Controls.Add($lookupButton)

Function VerseLookup {
    $book = $bookComboBox.Text
    $chapter = $chapterTextBox.Text
    $verse = $verseTextBox.Text
    $BibleVerse = New-WebServiceProxy -uri "http://www.webservicex.net/BibleWebservice.asmx?WSDL"
    $theVerse = [xml]$BibleVerse.GetBibleWordsByChapterAndVerse($book,$chapter,$verse)
    $Selection  = $theVerse.NewDataSet.Table | Select BibleWords
    $verseOutputBox.Text = $Selection.BibleWords
}

This is an example of the returned XML from the SOAP call.

<?xml version="1.0" encoding="utf-16"?>
<NewDataSet>
  <Table>
    <Book>1</Book>
    <BookTitle>Genesis</BookTitle>
    <Chapter>1</Chapter>
    <Verse>1</Verse>
    <BibleWords>In the beginning God created the heaven and the earth.</BibleWords>
  </Table>
</NewDataSet>

Because this script makes a Web Services call before it opens the form it can take several seconds to run. WebserviceX.net is usually reasonably responsive but does occasionally you will get a long delay or even a timeout. In any case the lookups calling a Web Service will always take a few moments to many seconds to respond because of the external call.

BibleVerseLookup

BibleVerseLookup.ps1

Advertisements