Web Services Stumbling Blocks

Microsoft has done a great deal to ease the process of building Web Services, especially in Visual Studio .NET. But let’s focus on using just the .NET framework tools here.

First you’ll take a look at a simple Web Service. Then we’ll identify areas where you might have problems. Listings 13.113.4 serve as examples of the code that you will need to get started.

Listing 13.1. ASMX Code (C#)
<%@ WebService Language="c#" Codebehind="Service1.asmx.cs" 
Class="chap_13_c. TimeService" %%> 

Listing 13.2. Simple Web Service (C#)
using System; 
using System.Web.Services; 

namespace chap_13_c 
{
      //Create a class and inherit the WebService functionality 
public class TimeService : System.Web.Services.WebService 
      {
             //Constructor 
             public TimeService() 
             {
             } 
//This is required to make the following method SOAP   enabled 
             [WebMethod] 
             public string GetTime() 
             {
                return DateTime.Now. ToString(); 
             } 
      } 
} 

Listing 13.3. ASMX Code (Visual Basic .NET)
<%@ WebService Language="vb" Codebehind="Service1.asmx.vb" 
Class="chap_13_vb.Service1" %%> 

Listing 13.4. Simple Web Service (Visual Basic .NET)
Imports System 
Imports System.Web.Services 

Public Class TimeService 
    Inherits System.Web.Services.WebService 

    <WebMethod()> Public Function GetTime() As String 
        HelloWorld = Date.Now. ToString() 
    End Function 

End Class 

If you look at Listings 13.113.4 , you will notice that you have to produce very little code to create a simple Web Service. Let’s take a look at where you might run into problems and how to resolve them.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset