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  
Silverlight  
Visual Basic.NET  
Windows Scripting  
Windows Security  
XML  
Mobile Linux 
App Generation ROI 
IBM® developerWorks 
ASP Web Hosting  
ASP.NET Web Hosting 
Windows Web Hosting
 
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 / 10
    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


    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

    - User-defined Functions using Visual Basic Ap...
    - Understanding Object Binding in VBA
    - Mastering the Message Box
    - Testing a Windows Forms Application
    - Using Visual Basic.NET Features to Code a Wi...
    - Correcting Code in a Windows Forms Applicati...
    - Write Readable Code and Comments for Windows...
    - How to Code and Test a Windows Forms Applica...
    - Adding Features to a Windows Forms Applicati...
    - How to Design a Windows Forms Application
    - LINQ to XML Programming Using Visual Basic.N...
    - Understanding Delegates using Visual Basic.N...
    - Create a Sudoku Puzzle Generator using VB.NET
    - Entity Creation and Messaging in a VB.NET Te...
    - Movement and Player Statistics in a VB.NET T...





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 5 Hosted by Hostway
    Stay green...Green IT