Visual Basic.NET
  Home arrow Visual Basic.NET arrow Page 3 - Encoding/Decoding Web Service: Web Service...
ASP Free Forums 
.NET  
ASP  
ASP Code  
ASP.NET  
ASP.NET Code  
BrainDump  
C#  
Code Examples  
Database  
Database Code  
IIS  
Microsoft Access  
MS SQL Server  
Visual Basic.NET  
Windows Scripting  
Windows Security  
XML  
ASP Web Hosting  
ASP.NET Web Hosting 
Dedicated Servers 
Actuate Whitepapers 
Moblin 
Windows Web Hosting
 
IBM® developerWorks 
Sun Developer Network 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
VISUAL BASIC.NET

Encoding/Decoding Web Service: Web Service Provider
By: Jayaram Krishnaswamy
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 9
    2006-01-10

    Table of Contents:
  • Encoding/Decoding Web Service: Web Service Provider
  • What Does the Service Do?
  • Configuring the Web Service
  • Local Testing

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT

    Free Web 2.0 Code Generator! Generate data entry and reporting .NET Web apps in minutes. Quickly create visually stunning, feature-rich apps that are easy to customize and ready to deploy. Download Now!

    Encoding/Decoding Web Service: Web Service Provider - Configuring the Web Service


    (Page 3 of 4 )

    In the VS 2003 create a new project by choosing File --> New--> Project from the File Menu item. This opens up the New Project window and highlights the Web Services as shown below. The default web service is WebService1. Change this to something different; in the present tutorial it is Hencode.

    Creating a web service project in VS 2003 IDE

    The project explorer view with this choice is shown here. To the usual references you will see the System.Web.Services reference is also added.  The Service1.asmx is the file that will contain the web methods that we are going to code.

    Project explorer of a Web service Project

    Service1.asmx is the file that will contain the web methods. This file has a design view as well as a code view, Service1.asmx.vb. We will not be using the design view but our code will be inserted into the Service1.asmx.vb pane.

    the code

    In VS 2003 the Service1.asmx will come with a sample method (although commented out), the well known HelloWorld() method. What we will be doing is creating two methods, one of them for encoding and the other for decoding functionality. Arguments have to be passed to these functions from the calling program (the Client). We will be looking at the client in part 2.

    Let's look at the default, Public Function HelloWorld() web method. All this function does is display "HelloWorld" to the client. It is very important to use the correct syntax. If there are more methods you will be calling more functions as we shall see later.

    '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
    ' Return "Hello World"
    'End Function

    In order to get the encoding functionality we will create an encoding function, enc() which takes a string as an argument and returns a string. For the reverse case we will be passing a string to a function called denc() that we create, which will provide a decoded string back. In each of these cases we will be using the methods of the System.Text.ASCIICoding.ASCII class for proper conversions and encoding/decoding. The two web methods are shown here:

    <WebMethod()> _
    Public Function enc (ByVal StrEncode As String)
    Dim encodedStr As String
    encodedStr = _
    Convert.ToBase64String(System.Text.ASCIIEncoding. _
    ASCII.GetBytes(StrEncode))
    Return (encodedStr)
    End Function


    <WebMethod()> _
    Public Function denc (ByVal StrDecode As String)
    Dim decodedStrg As String
    decodedStrg = System.Text.ASCIIEncoding.ASCII. _
    GetString(Convert.FromBase64String(StrDecode))
    Return decodedStrg
    End Function

    With this accomplished the Web Service provider is complete. The next section shows how you may test it within the VS 20043 IDE. However, for client access you may have to build a project so that they may access this service over the web. That will be described in part 2.

    More Visual Basic.NET Articles
    More By Jayaram Krishnaswamy


       · Web Services has ushered in a new era in IT. It nicely fits into the growing area of...
     

    VISUAL BASIC.NET ARTICLES

    - Movement and Player Statistics in a VB.NET T...
    - Creating and Drawing a Game Map in VB.NET
    - Working with Classes and Properties for Game...
    - Working with Loops, Arrays, and Collections ...
    - Learning Loops in VB.NET for Game Development
    - Learning VB.NET: Working with Variables, Con...
    - The Basics of VB.NET Through Text Game Devel...
    - Learning VB.NET Through Text Game Development
    - Types of Operators in Visual Basic
    - Operators
    - Understanding Custom Events using Visual Bas...
    - Polymorphism using Abstract Classes in Visua...
    - Shadowing using Shadows in Visual Basic.NET ...
    - Overloading and Overriding in Visual Basic.N...
    - More on Controlling Windows Fax Services Usi...





    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway