It's Not A Bug, It's A Feature Just another Developer weblog

12Jun/101

SmarterTrack VB.Net Login Provider Webservice

Here is a sample VB.Net web service for use with the Smarter Tools Smarter Track Customer Service Portal. I Looked around the net for a working VB.Net version of this since we are using this software were I work and wanted to allow our customers to login to the portal with thier existing user name and password so they would not have to remember or register a separate account to interact with our customer service department.

Unfortunately it seems there are more C# programmers than us die hard VB programmers (coming from a background of writing Classic VB script for 15 years, I have no desire on learning to write C#). So after getting this to work I thought I would pass it along to the community to use an abuse.

One import note about this code, for some reason the programmers at Smater Tools decided it was mandatory for the Login Provider web service to use the Namespace 'http://tempuri.org/' so if you change it in the sample code, It wont work. Don't ask me why, it just wont.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
Imports System.Web.Services
Imports System.Web.Services.Protocols
Imports System.ComponentModel
Imports SmarterTrack.Connector
Imports System.Data
Imports System.Data.SqlClient

' To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.
' <System.Web.Script.Services.ScriptService()> _
<System.Web.Services.WebService(Namespace:="http://tempuri.org/")>
<System.Web.Services.WebServiceBinding(ConformsTo:=WsiProfiles.BasicProfile1_1)> _
<ToolboxItem(False)> _
Public Class LoginProvider
    Inherits System.Web.Services.WebService
    Implements IExternalLoginProvider

    Private Const WebServiceAuth As String = "myPassword"

#Region "Login Provider"
    '###############################################################

    <WebMethod()> _
    Public Function Authenticate(ByVal inputs As SmarterTrack.Connector.ExternalLoginProviderInputs) As SmarterTrack.Connector.ExternalLoginProviderResult Implements SmarterTrack.Connector.IExternalLoginProvider.Authenticate
        Dim iData As New ParsedLoginInputData(inputs)
        Dim result As New ExternalLoginProviderResult()
        Dim SQLConn As New SqlConnection()
        Dim SQLCmd As New SqlCommand()

        ' Verify that all necessary criteria to call this function are met
        If iData.WebServiceAuthorizationCode <> WebServiceAuth Then
            Return New ExternalLoginProviderResult(False, "Permission Denied")
        End If
        If String.IsNullOrEmpty(iData.LoginUsername) OrElse String.IsNullOrEmpty(iData.LoginPassword) Then
            Return New ExternalLoginProviderResult(False, "Required Input Missing")
        End If

        SQLConn = New SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings("Conn").ToString())
        SQLConn.Open()
        SQLCmd = New SqlCommand("SELECT TOP 1 Email, Name FROM Accounts WHERE Email = @Email and Password = @Password", SQLConn)
        SQLCmd.Parameters.Add("@Email", SqlDbType.VarChar)
        SQLCmd.Parameters("@Email").Value = iData.LoginUsername
        SQLCmd.Parameters.Add("@Password", SqlDbType.VarChar)
        SQLCmd.Parameters("@Password").Value = iData.LoginPassword
        Dim AccountInfo As SqlDataReader = SQLCmd.ExecuteReader()
        If AccountInfo.HasRows Then
            While AccountInfo.Read()
                result.Success = True
                result.Message = "Login Successful"
                result.OutputVariables.Add("Authentication=OK")
                result.OutputVariables.Add("EmailAddress=" & AccountInfo.Item("Email"))
                ' optional
                result.OutputVariables.Add("DisplayName=" & AccountInfo.Item("Name"))
            End While
        Else
            result.Success = False
            result.Message = "Login Failed"
        End If
        AccountInfo.Close()
        SQLCmd.Dispose()
        SQLConn.Dispose()
        Return result
    End Function

    <WebMethod()> _
    Public Function GetSignInCookieInfo(ByVal inputs As SmarterTrack.Connector.ExternalLoginProviderInputs) As SmarterTrack.Connector.ExternalLoginProviderResult Implements SmarterTrack.Connector.IExternalLoginProvider.GetSignInCookieInfo
        Dim result As New ExternalLoginProviderResult()
        Return New ExternalLoginProviderResult(False, "Method Not Implemented")
        Return result
    End Function
#End Region
End Class

I have to say I have been impressed with the Smarter Track Software, we have been using the customer service chat side of the system for about a year now and has had a tremendous impact on our business. Only recently did I discover its full potential. mainly because the software was installed and configured by our previous IT director who never mentioned it had a complete ticketing system along with the chat. and When I had to re-new our license a couple of months ago realized what we had.

So now I am in the process of integrating it with our existing systems to be implemented fully in the next few weeks. Since our current sites are all written in Classic ASP, I did not implement the 'GetSignInCookieInfo' functionality since it it meant to be used with a DOT.NET site and we just don't have the need for it.

If you have any need for a Customer Service portal and don't want to spend tens of thousands of dollars you should really look into this system. Obviously you will need a copy of the Smarter Track software installed to use and test this webservice.

But one of the really great things about Smarter Track is that you can install it on a server without a license key (developer mode). and it will allow you full access to all the features of the system, but only allows you to have have one customer service Representative account. Feel free to download it and check it out.