Results 1 to 9 of 9

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

  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]

  2. #2
    PowerPoster hellswraith's Avatar
    Join Date
    Jul 2002
    Location
    Washington St.
    Posts
    2,464
    My first thought is you are over designing this system. When I have more time to give it more thought, I will try to post.

  3. #3
    Fanatic Member
    Join Date
    May 2001
    Posts
    837
    I structured an app of mine similiar to that. It sounded like a really good design to me. What I did was have my ASP.NET page contact a webservice for everything, and the webservice called stored procedures in the database. My company wanted a way to input timesheet hours over the web, but I also wanted to write a standard EXE for my computer that would be more automatic. On the web you would enter your project and the number of hours you worked each day. But on my desktop you would select the project and then click start and stop throughout the day as you worked, and at the end of the day it would contact the web service and update my hours. Only problem was halfway through development I found out they had someone else build half an app in lotus notes among other lesser languages so I'm waiting to see what managment decides. Screwy.
    The human brain cannot hold all of the knowledge that exists in this world, but it can hold pointers to that knowledge.

  4. #4
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687
    Using the DB access as a Web Service maynot be such a hot idea- it leaves it open to the world. BUT, you can create it as a Com/MTS object that then sits inside the firewall (and subsequently is protected from outside intervention). Then again, maybe it's just me.

    TG
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  5. #5
    Fanatic Member
    Join Date
    May 2001
    Posts
    837
    the webservice uses windows security, supposedly. I haven't tested it but I don't think you're allowed access unless you have a windows account?
    The human brain cannot hold all of the knowledge that exists in this world, but it can hold pointers to that knowledge.

  6. #6
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687
    That's what it runs as.... but to send it info to process..... don't know.

    TG
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  7. #7

    Thread Starter
    Retired VBF Adm1nistrator plenderj's Avatar
    Join Date
    Jan 2001
    Location
    Dublin, Ireland
    Posts
    10,359
    My web services will be running on a server not accessible from the outside world - so DB access etc. should be safe
    Microsoft MVP : Visual Developer - Visual Basic [2004-2005]

  8. #8
    Fanatic Member
    Join Date
    Oct 2001
    Location
    Three Anchor Bay, Cape Town, South Africa
    Posts
    769
    I'm with HellsWraith! Way overkill for what you are doing. But, if the design is all you are looking at...

    Sifting through all the code and other blerb, I see the real question being
    shouldn't the database code be removed from any business logic?
    I would say the answer is yes. Your business logic is one logical layer while your database code (persistence) is another logical layer. But in your eg. I dont see any business logic to speak of. What you are doing is more an import function. What you should be doing is some serious format checking when you receive the data. This is where XML is the way you should be going! You would check the input against an XSL to make sure the data is in a valid format. Much better than writing your own format checking!

    Something to remember. In B2B integration, its all about format and data validity!

    NOOOO! SQL concatenation! NOOOO! You are leaving yourself wide open for some SQL injection attack! Parameterise! Parameterise! Parameterise!

  9. #9
    Fanatic Member
    Join Date
    Oct 2001
    Location
    Three Anchor Bay, Cape Town, South Africa
    Posts
    769
    Sorry,
    check the input against an XSL
    in the previous post should be "check the input against an XSD "

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