Results 1 to 9 of 9

Thread: ASP.Net n-tier Design Thoughts...

Threaded View

  1. #1

    Thread Starter
    Retired VBF Adm1nistrator plenderj's Avatar
    Join Date
    Jan 2001
    Location
    Dublin, Ireland
    Posts
    10,359

    ASP.Net n-tier Design Thoughts...

    Righty.

    I am working on a personal project at the moment, so have total free range on all design issues.
    Basically, a telecomms operator will connect to my service and pass some data by HTTP POST.
    I then connect back once I have generated a response and I sent that back by HTTP POST.
    When they send me the HTTP POST data I have to reply with either "Success" for "Failure" - depending on whether my service has accepted the message okay.

    Here comes the interesting parts. How to get the data through to my SQL Server.
    So. My idea was that I could have an interface page - SMSInterface.aspx
    That accepts the HTTP POST data.

    Then I pass the data to a method of a web service SMSHandler.asmx and wait for a response - True or False.
    Here is where I have few options, and I'm not quite sure.
    What I'm doing is passing the data, in SMSHandler.asmx into the SQL Server, and if there are no errors then return True.
    If there were any errors then return False.

    That boolean true or false is returned to the SMSInterface.aspx file, and then it sends Success or Failure to the client browser.
    This is the SMSInterface.aspx file :

    VB Code:
    1. Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    2.         Dim SMSHandler As New x.localhost.SMSHandlerService()
    3.         With Request            
    4.             If SMSHandler.SubmitSMS(Request.Form("Channel"), Request.Form("Reference"), Request.Form("Trigger"), Request.Form("Shortcode"), Request.Form("Phone"), Request.Form("Content"), Request.Form("PayloadType"), Request.Form("DateReceived"), Request.Form("CampaignID")) Then
    5.                 strPageData = "Success"
    6.             Else
    7.                 strPageData = "Fail"
    8.             End If
    9.         End With
    10.     End Sub

    This is the SMSHandler Service :
    VB Code:
    1. <WebMethod()> Public Function SubmitSMS(ByVal strChannel As String, ByVal strReference As String, ByVal strTrigger As String, ByVal strShortcode As String, ByVal strPhone As String, ByVal strContent As String, ByVal strPayloadType As String, ByVal strDateReceived As String, ByVal strCampaignID As String) As Boolean
    2.         Dim blnRetVal As Boolean = True, strSQLStatement As String, mySQLConnection As SqlConnection
    3.         Dim mySQLAdapter As SqlDataAdapter, mySQLDataSet As DataSet
    4.         Dim mySQLCommand As SqlCommand
    5.  
    6.         Try
    7.             mySQLConnection = New SqlConnection(ConnectionString)
    8.             mySQLConnection.Open()
    9.         Catch ex As Exception
    10.             blnRetVal = False
    11.             DespatchError(ex)
    12.             GoTo eof
    13.         End Try
    14.  
    15.         strSQLStatement = "INSERT INTO tblIncomingMessages VALUES (" & Apostrophise(strChannel, strReference, strTrigger, strShortcode, strPhone, strContent, strPayloadType, strDateReceived, strCampaignID) & ")"
    16.  
    17.         Try
    18.             mySQLCommand = New SqlCommand(strSQLStatement, mySQLConnection)
    19.             mySQLCommand.ExecuteNonQuery()
    20.         Catch ex As Exception
    21.             blnRetVal = False
    22.             DespatchError(ex)            
    23.             GoTo eof
    24.         End Try
    25.  
    26. eof:
    27.         Return blnRetVal
    28.     End Function
    29.  
    30.     Private Function Apostrophise(ByVal ParamArray strVars As String()) As String
    31.         Dim i As Long, strRetVal As String
    32.         For i = 0 To strVars.Length - 1
    33.             strRetVal &= "'" & Replace(strVars(i), "'", "^") & "', "
    34.         Next
    35.         Return Left(strRetVal, Len(strRetVal) - 2)
    36.     End Function
    37.  
    38.     Private Sub DespatchError(ByVal ex As Exception)
    39.         WriteToFile(vbCrLf & "***" & Now & "***" & vbCrLf & vbCrLf, "error.log")
    40.         WriteToFile(ex.ToString, "error.log")
    41.     End Sub
    42.  
    43.     Private Sub WriteToFile(ByVal strData As String, ByVal strFilePath As String)
    44.         Dim sw As New StreamWriter(AppLocalPath & strFilePath, True)
    45.         sw.WriteLine(strData)
    46.         sw.Close()
    47.     End Sub

    So its not very difficult - nothing complicated there.
    What I'm thinking though, is that, in an n-tier design, shouldn't the database code be removed from any business logic?
    So perhaps I should change SMSHandler.asmx such that there's no DB code in it, as above, and instead instantiate a reference to another web service.
    And that web service would purely handle database requests.

    Any thoughts?

    I was also thinking that if this project takes off, and the database is put onto a different server - then this decision will may make an impact as follows:
    I've got my web server, and I've got my DB Server.
    If the database access code is on the web server, then its ado.net database access data going over the network.
    But if the database access code is on the DB Server, and is instantiated as a method to a web service from the web server, then its SOAP/XML going over the network.
    So which would be faster, database data streaming across the network, or SOAP/XML going across?


    I know in my heart that this is all nearly irrelevant, but I just wanted to know what any of you thought about it from a design point of view...?
    Last edited by plenderj; Jul 21st, 2004 at 03:19 PM.
    Microsoft MVP : Visual Developer - Visual Basic [2004-2005]

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width