At this point, save the project and right-click service1.asmx in the Project Explorer. Then, select Set as Start Page and press F5. The page displayed in Internet Explorer looks like the page in Figure 11-3. Depending on the operating system, the information listed below the GetAllEmployees link may or may not be displayed.
Figure 11-3: Your first Web service interface
.NET creates this page so people can gather information about the Web service. Notice that the GetAllEmployees method is listed here. Click the GetAllEmployees link. This presents you with another Web page that contains a SOAP request and response message as well as an HTTP GET request and response message. However, all you really care about is the top part of the Web page, as shown in Figure 11-4.
Figure 11-4: The GetAllEmployees test screen
Because this method takes no parameters, you are simply presented with an Invoke button. Click the button and take a look at the output, which is partially displayed in Listing 11-6.
Listing 11-6: Partial Output from the GetAllEmployees Method
<?xml version="1.0" encoding="utf-8" ?> - <DataSet xmlns="http://tempuri.org/"> - <xs:schema bold">NewDataSet" xmlns="" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata"> - <xs:element name="NewDataSet" msdata:IsDataSet="true"> - <xs:complexType> - <xs:choice maxOccurs="unbounded"> - <xs:element name="Table"> - <xs:complexType> - <xs:sequence> <xs:element name="EmployeeID" type="xs:int" minOccurs="0" /> <xs:element name="LastName" type="xs:string" minOccurs="0" /> <xs:element name="FirstName" type="xs:string" minOccurs="0" /> <xs:element name="Title" type="xs:string" minOccurs="0" /> </xs:sequence> </xs:complexType> </xs:element> </xs:choice> </xs:complexType> </xs:element> </xs:schema> - <diffgr:diffgram xmlns:msdata="urn:schemas-microsoft-com:xml-msdata" xmlns:diffgr="urn:schemas-microsoft-com:xml-diffgram-v1"> - <NewDataSet xmlns=""> - <Table diffgr:bold">Table1" msdata:rowOrder="0"> <EmployeeID>1</EmployeeID> <LastName>Davolio</LastName> <FirstName>Nancy</FirstName> <Title>Sales Representative</Title> </Table> - <Table diffgr:bold">Table2" msdata:rowOrder="1"> <EmployeeID>2</EmployeeID> <LastName>Fuller</LastName> <FirstName>Andrew</FirstName> <Title>Vice President, Sales</Title> </Table>
Even if you have never seen an XSD document before, this should still be fairly easy to understand. Everything in the xs:schema tags describes the format of the data. Following this you can see the records from your employee table. Remember that your proxy method only returns a partial list of employee data.
Note | One thing to be aware of is the tag that reads <XS:complexType>. Any complex return type is not likely to be easily understood by any other language. In other words, something such as a dataset could be easily read and understood by a .NET language, but Java has no concept of a dataset. A Java application could read this because it is just plain text, but being able to do something useful with it (such as create a dataset out of the content) is far more difficult. This is important to remember when creating Web services that will be read by other applications within an enterprise. |
You have just created your first Web service—and with no pain at all!