Calling a Web Service using VB6 with SOAP 3.0 - Example 3: SOAP client calling the Enc/Denc web service
(Page 4 of 4 )
The second web service considered is a service that has two defined methods. The service takes a string and returns its encoded value as the first method (Enc()) and the second method (denc()) takes a given value and returns its de-encoded value. Please review this tutorial regarding this service. The web service code is created using VB.NET and summarized in the following code listing:
Imports System.Web.Services
<System.Web.Services.WebService(Namespace := "http://tempuri.org/
Hencode/Service1")> _
Public Class Service1
Inherits System.Web.Services.WebService
#Region " Web Services Designer Generated Code "
Public Sub New()
MyBase.New()
'This call is required by the Web Services Designer.
InitializeComponent()
'Add your own initialization code after the InitializeComponent()
call
End Sub
'Required by the Web Services Designer
Private components As System.ComponentModel.IContainer
'NOTE: The following procedure is required by the Web Services Designer
'It can be modified using the Web Services Designer.
'Do not modify it using the code editor.
<System.Diagnostics.DebuggerStepThrough()> Private Sub
InitializeComponent()
components = New System.ComponentModel.Container()
End Sub
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
'CODEGEN: This procedure is required by the Web Services Designer
'Do not modify it using the code editor.
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub
#End Region
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
End Class
Create a project and a command button to the default form. To the click event of the button add the code shown here. The client once declared can be used for all the methods the service provides.
Private Sub Command1_Click()
Dim clnt As New SoapClient30
Dim strsvc As String
'the client is initialized
clnt.MSSoapInit "http://localhost/Hencode/Service1.asmx?wsdl"
'the client calls the enc method of the service
strsvc = clnt.Enc ("Mysorian")
'the result returned from the web service is sent to message box
MsgBox (strsvc)
Dim orig As String
'the client is called now with denc method of the web service
'the denc takes the string produced by the first call to enc
'the idea is to reproduce the original string
orig = clnt.denc(strsvc)
MsgBox (orig)
End Sub
If you run the above code, you will first get an encoded value, and in the second message your original is recovered as shown.


Summary
SOAP 3.0 will be used by those who cannot afford, or do not want to implement, the .NET framework as the programming backbone. It is also quite useful to those developers who want to use their VB 6 skills. The method does not have the excellent support of the built-in web service discovery tool in VS 2003, but necessary information may be obtained from the web reference (WSDL). It is possible to use either of the CreateObject() or NEW instantiation schemes.
| DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware. |
|
| · | | | · | | | · | | | · | | | · | | | · | | | · | | | · | | | · | | | · | | | · | | | · | | | · | | | · | | | · | | | · | | | | |
|