How To Lookup Key Code on Internet Server


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 14 of 14

Thread: How To Lookup Key Code on Internet Server

  1. #1
    Join Date
    Aug 2004
    Location
    Orange, California
    Posts
    1,261

    How To Lookup Key Code on Internet Server

    I am writing an Installer program that needs to accept a Key Code from the user and validate that it has not been used before by checking and updating a record in a database on a web server.

    This is new for this customer and so he plans on using SQL Server on his webserver. The webserver will generate the Keycode and e-mail it to the user.

    The Idea is to connect to the database on his webserver and validate that the KeyCode exists and that the install count is zero. After the program is installed the installer must update the install count.

    I have done database stuff before but never accross the internet?

    Thanks in advance for your help!

  2. #2
    Join Date
    Nov 2003
    Location
    Portland, OR
    Posts
    8,387
    Phil Weber
    http://www.philweber.com

    Please post questions to the forums, where others may benefit.
    I do not offer free assistance by e-mail. Thank you!

  3. #3
    Join Date
    Aug 2004
    Location
    Orange, California
    Posts
    1,261
    I have no idea what OData is nor how to use it. From the little bit of the videos I started to watch it looked more like trying to squash an ant with a wrecking ball....very much over kill.

    I just need to validate a keycode. I am not building a web app. Not really.
    My customer does not have the money or the time for me to lean this new technology.

    I just need to do the following:
    1. Make sure internet connection is working
    2. connect to his database
    3. find the Keycode and get install count
    4. after succesful install update the install count.
    It needs to be fast and basically invisable to the user

    The idea is to allow the user to download the program but only be able to install it once.

  4. #4
    Join Date
    Nov 2003
    Location
    Portland, OR
    Posts
    8,387
    It's really not that bad. I created a simple database with a single table called KeyCodes:
    Code:
    Key     Column          Type
    ----    -----------    ------------
     X       KeyCode        VarChar(16)
              InstallCount    int
    Then I followed these steps to create a WCF Data Service, referring to my KeyCodes database instead of Northwind: http://msdn.microsoft.com/en-us/library/dd728275.aspx

    Finally, I wrote the client:
    Code:
    Imports System.IO
    Imports System.Net
    Imports System.Text
    
    Module Program
        Public Sub Main()
    
            Dim KeyCode As String = "12345"
            Const GetInstallCountUrl As String = "http://localhost:12345/KeyCodes.svc/KeyCodes('{0}')/InstallCount/$value/"
            Const SetInstallCountUrl As String = "http://localhost:12345/KeyCodes.svc/KeyCodes('{0}')/InstallCount"
    
            ' Get install count for key code
            Dim GetInstallCountRequest As New WebClient
            Dim GetInstallCountResponse As String = GetInstallCountRequest.DownloadString(String.Format(GetInstallCountUrl, KeyCode))
    
            Dim InstallCount As Integer
            If Integer.TryParse(GetInstallCountResponse, InstallCount) Then
                If InstallCount > 0 Then
                    ' Key code already installed
                Else
                    ' TODO: Perform install here
    
                    ' Increment install count
                    Dim SetInstallCountDoc As XDocument =
                        <?xml version="1.0" encoding="utf-8" standalone="yes"?>
                        <InstallCount xmlns="http://schemas.microsoft.com/ado/2007/08/dataservices"><&#37;= InstallCount + 1 %></InstallCount>
    
                    Dim Encoding As New ASCIIEncoding
                    Dim SetInstallCountData() As Byte = Encoding.GetBytes(SetInstallCountDoc.ToString())
    
                    Dim SetInstallCountRequest As HttpWebRequest = HttpWebRequest.Create(String.Format(SetInstallCountUrl, KeyCode))
                    SetInstallCountRequest.Method = "PUT"
                    SetInstallCountRequest.ContentLength = SetInstallCountData.Length
                    SetInstallCountRequest.ContentType = "application/xml"
                    Dim RequestStream As Stream = SetInstallCountRequest.GetRequestStream()
                    RequestStream.Write(SetInstallCountData, 0, SetInstallCountData.Length)
    
                    ' Get new count to make sure it worked
                    ' GetInstallCountResponse = GetInstallCountRequest.DownloadString(String.Format(GetInstallCountUrl, KeyCode))
                End If
            End If
    
        End Sub
    End Module
    Phil Weber
    http://www.philweber.com

    Please post questions to the forums, where others may benefit.
    I do not offer free assistance by e-mail. Thank you!

  5. #5
    Join Date
    Aug 2004
    Location
    Orange, California
    Posts
    1,261
    Nice, but I can't follow those steps. I only have the Express version of VB which does not come with those templates. Express edition only has 3 templates. Windows App, Colsole App, and Class Library.

  6. #6
    Join Date
    Nov 2003
    Location
    Portland, OR
    Posts
    8,387
    Ah, well that will be a problem.

    You can connect to an instance of SQL Server over the Internet just like you can on a network: you just specify the server's IP address in the connection string. The server must be listening for connections on a TCP port that's not blocked by a firewall, and all users of your application must also be able to connect on that port. That's why I recommend a Web service, which uses port 80 like any other Web site.
    Phil Weber
    http://www.philweber.com

    Please post questions to the forums, where others may benefit.
    I do not offer free assistance by e-mail. Thank you!

  7. #7
    Join Date
    Nov 2003
    Location
    Portland, OR
    Posts
    8,387
    It looks like Visual Web Developer Express allows you to create WCF Data Services: http://www.microsoft.com/express/Web/. You can create the service in Visual Web Developer, then create the client in VB Express Edition.
    Phil Weber
    http://www.philweber.com

    Please post questions to the forums, where others may benefit.
    I do not offer free assistance by e-mail. Thank you!

  8. #8
    Join Date
    Aug 2004
    Location
    Orange, California
    Posts
    1,261
    Interesting?
    It forces you to install the Web Platform Installer stuff first and then it says it will start the Visual Web Developer Express install automatically when you finish with the web platform installer, but it never actually does the Visual Web Developer Express Install.

    Also it never explains what all the other stuff is and weather or not you need any of them???
    Since you have to choose something to get it to do the install I chose the Microsift MebMatrix. Should I install any of the other stuff?

  9. #9
    Join Date
    Nov 2003
    Location
    Portland, OR
    Posts
    8,387
    I wouldn't install any of the other stuff unless you know you need them. Do you have a version of SQL Server installed? If not, you may want to install SQL Server Express; you'll need to create a database that matches the one on your customer's Web server in order to create a WCF Data Service.
    Phil Weber
    http://www.philweber.com

    Please post questions to the forums, where others may benefit.
    I do not offer free assistance by e-mail. Thank you!

  10. #10
    Join Date
    Aug 2004
    Location
    Orange, California
    Posts
    1,261
    Yes, I already have SQL Server Express 2008 R2 Installed.
    But again Visual Web Developer Express never installed???

  11. #11
    Join Date
    Aug 2004
    Location
    Orange, California
    Posts
    1,261
    Well I got Visual Web Developer Express Installed. I went to this link http://www.microsoft.com/express/Downloads/ and it installed correctly, whereas installing from the other link did not work.

  12. #12
    Join Date
    Aug 2004
    Location
    Orange, California
    Posts
    1,261
    Ok I got everything installed and did the setup steps; but when I created a VB Consol App Project and plugged in your code.
    VB fails on the statement below:

    Dim GetInstallCountResponse As String = GetInstallCountRequest.DownloadString(String.Format(GetInstallCountUrl, KeyCode))


    Here is the section where I made a few minor changes:
    Dim KeyCode As String = "tester"
    Const GetInstallCountUrl As String = "http://localhost:12345/KeycodeDB.svc/KeyCodes('{0}')/InstallCount/$value/"
    Const SetInstallCountUrl As String = "http://localhost:12345/KeycodeDB.svc/KeyCodes('{0}')/InstallCount"

  13. #13
    Join Date
    Nov 2003
    Location
    Portland, OR
    Posts
    8,387
    What error do you get? What happens when you open a browser and navigate to http://localhost:12345/KeycodeDB.svc ?
    Phil Weber
    http://www.philweber.com

    Please post questions to the forums, where others may benefit.
    I do not offer free assistance by e-mail. Thank you!

  14. #14
    Join Date
    Aug 2004
    Location
    Orange, California
    Posts
    1,261
    Although it had nothing to do with the error VB did not like the XDocument definition statement until I added this additional Import:
    Imports System.Xml.Linq

    As far as the error goes it would not tell me the error. It said something abiut checking the responce object for the error. But I figered out what was wrong. I had to get into Web Developer and run the KeyCodeService project. It opens the default ASP.Net page in internet explorer and so long as I leave both running then the code works fine.

    Is this service going to be easy to install on my customers server?
    Last edited by Ron Weller; 06-06-2011 at 11:01 AM. Reason: typo

Similar Threads

  1. Replies: 12
    Last Post: 08-16-2005, 10:17 AM
  2. .NET equals Efficiency
    By Kevin in forum .NET
    Replies: 150
    Last Post: 03-04-2002, 05:40 PM
  3. asymetric encryption with private key
    By Eyup Gurel in forum Security
    Replies: 9
    Last Post: 01-24-2001, 06:12 PM
  4. server app
    By Alan Shiers in forum Java
    Replies: 1
    Last Post: 09-19-2000, 11:57 AM
  5. Replies: 7
    Last Post: 09-15-2000, 08:44 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center