Building a Web Service Using Visual Studio .NET


As you saw with the Visual Studio 6.0 example, building and consuming a Web service is pretty straightforward. Visual Studio .NET makes it even easier to work with Web services because it has built-in tools that can add references to existing Web services and built-in methods for building Web services. To get started with our Visual Studio .NET example, we'll migrate our Visual Basic 6.0 Web service to Visual Basic .NET.

To be honest, the migration is not all that difficult. The only change to the underlying code will be the code for generating the Web service. To create the Visual Studio .NET Web service, you just select the ASP.NET Web service under the Visual Basic projects in Visual Studio .NET, as shown in Figure 14-3. (You can also create Web services using C#, as you'll see in the next section.)

click to expand
Figure 14-3: Creating a Visual Basic .NET Web service project

Visual Studio .NET creates a stub of a sample HelloWorld service, which you can use as a starting point. Notice in the following code that the System.Web.Services namespace is imported and the WebService and WebMethod attributes are added to our application. The rest of the code is the same as in our Visual Studio 6.0 service, so I've left some of it out.

 Imports System.Web.Services      <WebService(Namespace := "http://tempuri.org/")> _ Public Class Service1     Inherits System.Web.Services.WebService               ' 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     <WebMethod()> Public Function GetFreeBusy(ByVal strDirURL As String, _     ByVal strUserNames As String, ByVal strStartDate As String, ByVal _     strEndDate As String, ByVal strInterval As String) As String    End Function          Private Function PrivGetFreeBusy(ByVal strUserName as String, _                                   ByVal strDirURL as String, _                                   ByVal strStartDate as String, _                                   ByVal strEndDate as String, _                                   ByVal strInterval as String) as String    End Function      End Class 

To test the .NET version of our Web service, all we do is make sure our .asmx file is the start page for our application and then run the application. Visual Studio .NET will then launch our application. Figure 14-4 shows the test page for our Web service. We can fill in the parameters and try the service to see if it works.

click to expand
Figure 14-4: Testing the Web service



Programming Microsoft Outlook and Microsoft Exchange 2003
Programming MicrosoftВ® OutlookВ® and Microsoft Exchange 2003, Third Edition (Pro-Developer)
ISBN: 0735614644
EAN: 2147483647
Year: 2003
Pages: 227
Authors: Thomas Rizzo

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