The next step is to create the equivalent of the LoadRecord method as a Web service. As before, this is a simple call to your already built objects. Add the code for this method, as shown in Listing 11-7.
Listing 11-7: The GetEmployeeDetails Web Method
<WebMethod()> Public Function GetEmployeeDetails(ByVal EmployeeID _ As Integer) As structEmployee Dim objEmployee As New EmployeeDC() Dim sEmployee As structEmployee sEmployee = objEmployee.LoadRecord(EmployeeID) objEmployee = Nothing Return sEmployee End Function
This method is different from your previous method in that it accepts a parameter and returns a structure instead of a dataset. Now run the application again. Figure 11-5 shows the Web interface to your Web services.
Figure 11-5: The updated Web service Internet Explorer interface
Selecting the GetEmployeeDetails link takes you to a Web page that looks like Figure 11-6.
Figure 11-6: The GetEmployeeDetails test screen
Notice that there is now a parameter list that accepts a value for the EmployeeID parameter. Enter the value 1 and click the Invoke button. Listing 11-8 shows the results.
Listing 11-8: The GetEmployeeDetails Results
<?xml version="1.0" encoding="utf-8" ?> - <structEmployee xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://tempuri.org/"> <EmployeeID>1</EmployeeID> <LastName>Davolio</LastName> <FirstName>Nancy</FirstName> <Title>Sales Representative</Title> <TitleOfCourtesy>Ms.</TitleOfCourtesy> <BirthDate>1948-12-08T00:00:00.0000000-08:00</BirthDate> <HireDate>1992-05-01T00:00:00.0000000-07:00</HireDate> <Address>507 - 20th Ave. E. Apt. 2A</Address> <City>Seattle</City> <Region>WA</Region> <PostalCode>98122</PostalCode> <Country>USA</Country> <HomePhone>(206) 555-9857</HomePhone> <Extension>5467</Extension> <Photo><Photo> <Notes>Education includes a BA in psychology from Colorado State University in 1970. She also completed "The Art of the Cold Call." Nancy is a member of Toastmasters International.</Notes> <ReportsTo>2</ReportsTo> <ReportsToFirstName>Andrew</ReportsToFirstName> <ReportsToLastName>Fuller</ReportsToLastName> <PhotoPath>http://accweb/emmployees/davolio.bmp</PhotoPath> - <Territories> <string>06897</string> <string>19713</string> </Territories> </structEmployee>
Note that I purposely omitted the values in the Photo tag because it takes up a large amount of space. An important thing to note is that there is no XSD schema with this SOAP response. Go back and look at the original Web page and take a look below at the SOAP response (shown in Listing 11-9).
Listing 11-9: The SOAP Response for the GetEmployeeDetails Method
HTTP/1.1 200 OK Content-Type: text/xml; charset=utf-8 Content-Length: length <?xml version="1.0" encoding="utf-8"?> <soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"> <soap:Body> <GetEmployeeDetailsResponse xmlns="http://tempuri.org/"> <GetEmployeeDetailsResult> <EmployeeID>int</EmployeeID> <LastName>string</LastName> <FirstName>string</FirstName> <Title>string</Title> <TitleOfCourtesy>string</TitleOfCourtesy> <BirthDate>dateTime</BirthDate> <HireDate>dateTime</HireDate> <Address>string</Address> <City>string</City> <Region>string</Region> <PostalCode>string</PostalCode> <Country>string</Country> <HomePhone>string</HomePhone> <Extension>string</Extension> <Photo>base64Binary</Photo> <Notes>string</Notes> <ReportsTo>int</ReportsTo> <ReportsToFirstName>string</ReportsToFirstName> <ReportsToLastName>string</ReportsToLastName> <PhotoPath>string</PhotoPath> <Territories> <string>string</string> <string>string</string> </Territories> </GetEmployeeDetailsResult> </GetEmployeeDetailsResponse> </soap:Body> </soap:Envelope>
It should be fairly clear from this code that the data type of each value is placed between the tags for the value. Also note that this return value is not denoted as a complex type.