Adding Sub Methods to a Web Service

A Web service is typically made up of many different methods. These methods can be either Subs or Functions. Functions return a value and Subs do not. This tip shows you how to define Subs in an ASP.NET Web service.USE 1T The methods created for this Web service add to the functionality of the Tips Web service. The Web service contains two Subs.The first Sub provides the method for adding a tip to the Access database. That method has this definition:

You start with the WebMethod tag, which indicates that the method is exposed through your Web service:

Also on that line, you indicate that the method is a Sub and its name is AddTip. The method has two parameters that need to be passed into it. The first is the title of the tip and the second is the text of the tip. Both must be passed in as strings.Since you need to add data to the database, you need these data objects:

and indicate that the Command object will connect to the database through the Connection object:

Next, you add a record to the database based on the title and text passed into this method:

The other Sub defined in this Web service allows for the deletion of a tip from the Access database:

This method needs to have a number passed into it, which is the ID of the tip that is to be deleted:

For this method, you will need data objects:

You start by connecting to the Access database:

You then delete the record that has an ID that matches the ID that was passed into this Sub:

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: