As your Web service becomes more complex, you will find that you need to import other namespaces into it. For example, if your Web service provided database functionality, you would need to import the necessary data namespaces. This tip shows you how to do that and how to use options within a Web service.
At the top of a Web service, you need to include these opening lines:
WebService Language="VB" Class="Tips" % > Imports System.Web.Services
After those lines of code but before you define your class, you can include Option directives like these:
The first directive tells the compiler that you do not want strict data-type conversion to be enforced. T urning this directive off means that you can easily place a number variable into a string variable.
The second option indicates that you will declare all your variables. Having this option on makes it easier for you to debug your code, since an error will be thrown if you try to reference a variable that you haven't defined.
After defining your option directives, you can import other namespaces into your Web service:
Imports System.Data Imports System.Data.OLEDB
Here, two data namespaces are added to the Web service. These allow you to connect to and retrieve data from an Access database. Notice that this is very different from the namespace directive used on an ASP.NET page.
No comments:
Post a Comment