Creating the GetAllEmployees Web Service


The first thing you will see is the design view (see Figure 11-2). The view looks a little strange, but the reason is straightforward—there is no user interface in a Web service!

click to expand
Figure 11-2: The Web service design interface

Switch to the code view so that you can really start working on your Web service. The first thing to note is the Imports line:

 Imports System.Web.Services 

All of the Web service functionality is contained in the System.Web.Services namespace. The second thing to note is the large block of text and code that has been commented out—the Hello World Web service:

 ' WEB SERVICE EXAMPLE ' The HelloWorld() example service returns the string Hello World. ' To build, uncomment the following lines then save and build the project. ' To test this web service, ensure that the .asmx file is the start page ' and press F5. ' '<WebMethod()> Public Function HelloWorld() As String '     HelloWorld = "Hello World" ' End Function 

This is probably included to show people how easy it is to create a Web service. The only difference between this method and any other method you have seen is the inclusion of the <WebMethod()> attribute tag in front of the method signature. At this point I can move on to the UDDI portion of the chapter because you have now implemented a Web service. Placing this attribute in front of a method exposes it as a Web service. That is all that is needed. However, the reality is that it is all of the other little things that are required to fully understand, find, and use Web services that are the somewhat more difficult parts of developing Web services. And you thought this chapter would be that easy.

Before creating your Web service, you need to add a reference to the NorthwindDC and NorthwindShared components. To do this, right-click the References node and select Add Reference. Click Browse and browse to the \bin folder in the Northwind folder. Select both DLLs and click OK. Next, add the following two Imports statements at the top of the code module:

 Imports NorthwindTraders.NorthwindShared.Structures Imports NorthwindTraders.NorthwindDC 

Then, delete the block of commented text and code and add the GetAllEmployees method shown in Listing 11-5.

Listing 11-5: The GetAllEmployees Method

start example
 <WebMethod()> Public Function GetAllEmployees() As DataSet      Dim objEmployee As New EmployeeDC()      Dim ds As DataSet      ds = objEmployee.LoadProxy      objEmployee = Nothing      Return ds End Function 
end example

This fairly straightforward method calls the LoadProxy method on your EmployeeDC object and returns the resulting dataset. In general, if you have built the components well enough, this is all that is required of a Web service—a set of interfaces available over the Web.




Building Client/Server Applications with VB. NET(c) An Example-Driven Approach
Building Client/Server Applications Under VB .NET: An Example-Driven Approach
ISBN: 1590590708
EAN: 2147483647
Year: 2005
Pages: 148
Authors: Jeff Levinson

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net