|
|
For the resume and job-opportunity postings to be of value, users must have a way to retrieve and view the postings. The Jobs web service provides two methods, one that retrieves a resume and one that retrieves a job opportunity:
byte() GetResume(string Category, string Description) byte() GetJobPosting(string Category, string Description)
The Jobs web service provides the CompanyEntries method that returns an array of strings that contains the names of companies that have posted job opportunities to the server:
<WebMethod()> Public Function CompanyEntries() As String() Dim Entries As String() Entries = Directory.GetDirectories("C:\Jobs\Postings") Dim I As Integer For I = 0 To Entries.Length - 1 Entries(I) = Path.GetFileName(Entries(I)) Next CompanyEntries = Entries End Function
As you can see, to return the names of companies that have posted job openings, the method first retrieves the names of folders that exist within the C:\Jobs\Postings folder. Next, the method parses off each folder’s directory path (removing the C:\Jobs\Postings\ that precedes the folder name).
In addition, the Jobs web service provides two methods that return resume entries for a specific job category and job opportunities for a specific company:
<WebMethod()> Public Function GetCategoryResumes(ByVal Category As _ Â String) As String() Dim Entries As String() Entries = Directory.GetFiles("C:\Jobs\Resumes\" & Category) Dim I As Integer For I = 0 To Entries.Length - 1 Entries(I) = Path.GetFileNameWithoutExtension(Entries(I)) Next GetCategoryResumes = Entries End Function <WebMethod()> Public Function GetCompanyPostings(ByVal Company As _ Â String) As String() Dim Entries As String() Entries = Directory.GetFiles("C:\Jobs\Postings\" & Company) Dim I As Integer For I = 0 To Entries.Length - 1 Entries(I) = Path.GetFileNameWithoutExtension(Entries(I)) Next GetCompanyPostings = Entries End Function
Each method simply returns the names of files (which correspond to the resume or job description) from the corresponding category or company folder. Listing 16.7 implements the GetResume and GetJobPosting methods.
Listing 16.7 Jobs.asmx.vb
![]() |
<WebMethod()> Public Function GetResume(ByVal Category As String, _ ByVal Description As String) As Byte() Dim Filename As String If (File.Exists("C:\Jobs\Resumes\" & Category & "\" & _ ÂDescription & ".RTF")) Then Filename = "C:\Jobs\Resumes\" & Category & "\" & _ ÂDescription & ".RTF" ElseIf (File.Exists("C:\Jobs\Resumes\" & Category & "\" & _ ÂDescription & ".XML")) Then Filename = "C:\Jobs\Resumes\" & Category & "\" & _ ÂDescription & ".XML" Dim DataSetObj As New DataSet() Try DataSetObj.ReadXml(Filename) Catch Ex As Exception Throw New Exception("Error accessing resume file") End Try Try Dim TempFilename As String = "C:\Jobs\Resumes\" & Category & _ Â "\Temp.RTF" Dim RTFData As String Dim I As Integer For I = 0 To DataSetObj.Tables(0).Columns.Count - 1 RTFData = RTFData & _ ÂDataSetObj.Tables(0).Columns(I).ColumnName & vbCrLf RTFData = RTFData & vbCrLf RTFData = RTFData & DataSetObj.Tables(0).Rows(0).Item(I) & _ ÂvbCrLf RTFData = RTFData & vbCrLf Next Dim OutputFile As New StreamWriter(TempFilename) OutputFile.Write(RTFData) OutputFile.Close() Filename = TempFilename Catch Ex As Exception Throw New Exception("Error writing RTF file") End Try Else Throw New Exception("Resume not found") End If Dim InputFile As FileStream Dim FileLength As Long Try InputFile = File.Open(Filename, FileMode.Open, _ Â FileAccess.Read) FileLength = InputFile.Length Dim DataBuffer(FileLength - 1) As Byte InputFile.Read(DataBuffer, 0, FileLength) InputFile.Close() File.Delete("C:\Jobs\Resumes\" & Category & _ Â "\Temp.RTF") GetResume = DataBuffer Catch Ex As Exception Throw New Exception("Error processing resume file") End Try End Function <WebMethod()> Public Function GetJobPosting(ByVal Company As String, _ ÂByVal Description As String) As Byte() Dim Filename As String If (File.Exists("C:\Jobs\Postings\" & Company & "\" & _ Â Description & ".RTF")) Then Filename = "C:\Jobs\Postings\" & Company & "\" & Description & _ Â".RTF" ElseIf (File.Exists("C:\Jobs\Postings\" & Company & "\" & _ Description & ".XML")) Then Filename = "C:\Jobs\Postings\" & Company & "\" & Description & _ Â".XML" Dim DataSetObj As New DataSet() Try DataSetObj.ReadXml(Filename) Catch Ex As Exception Throw New Exception("Error accessing resume file") End Try Try Dim TempFilename As String = "C:\Jobs\Postings\" & Company & _ Â "\Temp.RTF" Dim RTFData As String Dim I As Integer For I = 0 To DataSetObj.Tables(0).Columns.Count - 1 RTFData = RTFData & _ ÂDataSetObj.Tables(0).Columns(I).ColumnName & vbCrLf RTFData = RTFData & vbCrLf RTFData = RTFData & DataSetObj.Tables(0).Rows(0).Item(I) & _ ÂvbCrLf RTFData = RTFData & vbCrLf Next Dim OutputFile As New StreamWriter(TempFilename) OutputFile.Write(RTFData) OutputFile.Close() Filename = TempFilename Catch Ex As Exception Throw New Exception("Error writing RTF file " & Ex.Message) End Try Else Throw New Exception("Job posting not found") End If Dim InputFile As FileStream Dim FileLength As Long Try ÂInputFile = File.Open(Filename, FileMode.Open, _ FileAccess.Read) FileLength = InputFile.Length Dim DataBuffer(FileLength - 1) As Byte InputFile.Read(DataBuffer, 0, FileLength) InputFile.Close() File.Delete("C:\Jobs\Postings\" & Company & _ Â "\Temp.RTF") GetJobPosting = DataBuffer Catch Ex As Exception Throw New Exception("Error processing job posting file") End Try End Function
![]() |
If the client program requests an RTF-based resume or job description, the methods simply read and return the contents of the RTF file as a byte array. If the client program requests an XML-based resume or job description, the methods create a dataset object that contains the corresponding fields. Then, the methods build an RTF file using the field’s description and contents. The methods then read the contents of the RTF file.
The Visual Basic .NET program in Listing 16.8, DisplayJobPosting.vb, displays a form similar to that shown in Figure 16.8 that you can use to retrieve job opportunities that have been posted to the server.
Figure 16.8: Using the Jobs web service to retrieve job-opportunity postings
The program first uses the Jobs web service to retrieve the names of companies that have posted opportunities to the server. Then, if the user selects a company, the program will use the web service to list the opportunities the company has posted. Finally, if the user selects a specific posting, the program will use the Jobs web service to retrieve the specific posting.
To create the DisplayJobPosting.vb program, perform these steps:
Within Visual Studio .NET, select the File menu New Project option. Visual Studio .NET will display the New Project dialog box.
Within the New Project dialog box Project Types list, click Visual Basic Projects. Then, within the Templates field, click your mouse on Windows Application. Finally, within the Location field, specify the folder within which you want to store the program and the program name DisplayJobPosting. Select OK. Visual Studio .NET will display a form onto which you can drag and drop the program’s controls (label, buttons, and text box).
Using the Toolbox, drag and drop the button and text boxes, list box, label, and hyperlink label shown in Figure 16.8 onto the form.
Select the Project menu Add Web Reference option. Visual Studio .NET will display the Add Web Reference dialog box.
Within the Address field, type http://localhost/Jobs/Service1.asmx?WSDL (because the program does not require a secure connection, it uses http: as opposed to https:) and press Enter. The dialog box will load the file’s contents. Click on the Add Reference button.
Select the View menu Code option. Visual Studio .NET will display the program’s source code. Within the source code add the program statements in Listing 16.8.
Listing 16.8 DisplayJobPosting.vb
![]() |
Imports System.IO Dim Company As String Private Sub Page_Load(ByVal sender As System.Object, _ Â ByVal e As System.EventArgs) Handles MyBase.Load RichTextBox1.Text = "" Try Dim WS As New localhost.Service1() Dim Companies() As String Companies = WS.CompanyEntries() Dim Str As String If (ListBox1.Items.Count = 0) Then For Each Str In Companies ListBox1.Items.Add(Str) Next End If Catch Ex As Exception RichTextBox1.Text = Ex.Message End Try End Sub Private Sub Button1_Click(ByVal sender As System.Object, ByVal e _ Â As System.EventArgs) Handles Button1.Click If (ListBox1.SelectedItem Is Nothing) Then RichTextBox1.Text = "Must select company" Else Try Company = ListBox1.SelectedItem ' Company is global variable Dim WS As New localhost.Service1() Dim Postings() As String Postings = WS.GetCompanyPostings(Company) Dim Str As String If (ListBox2.Items.Count = 0) Then For Each Str In Postings ListBox2.Items.Add(Str) Next End If Catch Ex As Exception RichTextBox1.Text = Ex.Message End Try End If End Sub Private Sub Button2_Click(ByVal sender As System.Object, ByVal e _ Â As System.EventArgs) Handles Button2.Click If (ListBox1.SelectedItem Is Nothing) Then RichTextBox1.Text = "Must select company" ElseIf (ListBox2.SelectedItem Is Nothing) Then RichTextBox1.Text = "Must select job description" Else Try Dim WS As New localhost.Service1() Dim Data As Byte() Data = WS.GetJobPosting(Company, ListBox2.SelectedItem) Dim OutputFile As FileStream OutputFile = File.Open("TEMP.RTF", FileMode.Create, _ Â FileAccess.Write) OutputFile.Write(Data, 0, Data.Length) OutputFile.Close() RichTextBox1.LoadFile("TEMP.RTF") Catch Ex As Exception Try RichTextBox1.LoadFile("TEMP.RTF", _ ÂRichTextBoxStreamType.PlainText) Catch Ex As Exception RichTextBox1.Text = "Error loading resume file" End Try End Try End If End Sub
![]() |
After the program validates the user selections, the program will call the Jobs web service to retrieve the job posting. As discussed, the Jobs web service will return a byte array that contains the job posting. The program will write the array’s contents to a file in the current directory named Temp.RTF, which the program will then load into the RichTextBox to display the posting’s contents.
The Visual Basic .NET program in Listing 16.9, ShowResume.vb, displays the form shown in Figure 16.9 that a user can use to view a resume posting.
Figure 16.9: Using the Jobs web service to retrieve resume postings
When the program first runs, it will fill the list box with the various resume categories. If the user selects a specific category, the program will then use the web service to retrieve the names of individuals who have posted resumes to the corresponding entries. Finally, if the user selects a specific resume, the program will use the web service to retrieve the resume’s contents.
To create the ShowResume.vb program, perform these steps:
Within Visual Studio .NET, select the File menu New Project option. Visual Studio .NET will display the New Project dialog box.
Within the New Project dialog box Project Types list, click on Visual Basic Projects. Then, within the Templates field, click on Windows Application. Finally, within the Location field, specify the folder within which you want to store the program and the program name ShowResume. Select OK. Visual Studio .NET will display a form onto which you can drag and drop the program’s controls (label, buttons, and text box).
Using the Toolbox, drag and drop the button and text boxes, list box, label, and hyperlink label previously shown in Figure 16.9 onto the form.
Select the Project menu Add Web Reference option. Visual Studio .NET will display the Add Web Reference dialog box.
Within the Address field, type http://localhost/Jobs/Service1.asmx?WSDL (because the program does not require a secure connection, it uses http: as opposed to https:) and press Enter. The dialog box will load the file’s contents. Click your mouse on the Add Reference button.
Select the View menu Code option. Visual Studio .NET will display the program’s source code. Within the source code add the program statements in Listing 16.9.
Listing 16.9 ShowResume.vb
![]() |
Imports System.IO Dim Category As String Private Sub Page_Load(ByVal sender As System.Object, _ Â ByVal e As System.EventArgs) Handles MyBase.Load RichTextBox1.Text = "" Try Dim WS As New localhost.Service1() Dim Categories() As String Categories = WS.ResumeCategories() Dim Str As String If (ListBox1.Items.Count = 0) Then For Each Str In Categories ListBox1.Items.Add(Str) Next End If Catch Ex As Exception RichTextBox1.Text = Ex.Message End Try End Sub Private Sub Button1_Click(ByVal sender As System.Object, ByVal e _ Â As System.EventArgs) Handles Button1.Click If (ListBox1.SelectedItem Is Nothing) Then RichTextBox1.Text = "Must select company" Else Try Category = ListBox1.SelectedItem ' Category is global variable Dim WS As New localhost.Service1() Dim Resumes() As String Resumes = WS.GetCategoryResumes(Category) Dim Str As String If (ListBox2.Items.Count = 0) Then For Each Str In Resumes ListBox2.Items.Add(Str) Next End If Catch Ex As Exception RichTextBox1.Text = Ex.Message End Try End If End Sub Private Sub Button2_Click(ByVal sender As System.Object, ByVal e _ Â As System.EventArgs) Handles Button2.Click If (ListBox1.SelectedItem Is Nothing) Then RichTextBox1.Text = "Must select category" ElseIf (ListBox2.SelectedItem Is Nothing) Then RichTextBox1.Text = "Must select resume description" Else Try Dim WS As New localhost.Service1() Dim Data As Byte() Data = WS.GetResume(Category, ListBox2.SelectedItem) Dim OutputFile As FileStream OutputFile = File.Open("TEMP.RTF", FileMode.Create, _ Â FileAccess.Write) OutputFile.Write(Data, 0, Data.Length) OutputFile.Close() RichTextBox1.LoadFile("TEMP.RTF") Catch Ex As Exception Try RichTextBox1.LoadFile("TEMP.RTF", _ Â RichTextBoxStreamType.PlainText) Catch Ex2 As Exception RichTextBox1.Text = "Error loading resume file " & Ex2.Message End Try End Try End If End Sub
![]() |
The program will first validate the user selections. Then, the program will call the Jobs web service to retrieve the selected resume. The Jobs web service, in turn, will return a byte array that contains the resume that the program will write to a file in the current directory named Temp.RTF. The program will then load into the RichTextBox to display the posting’s contents.
|
|