1

For a web application, I am creating a SMS module that can send an SMS from the application. My SMS provider has an API that I can call over HTTP.

The API is called via an XmlTextReader who just reads the XML response from the API.

Now my problem is: When I send the SMS from a web page (basically just doing an HTTP request) it takes more than a minute before I receive the SMS.

But when I run the exact same code from a Windows console application, my SMS arrives in less then 5 seconds.

I have done multiple tests with this, and it's not really my SMS provider who is slow. Somehow, the HTTP request gets delayed from within the ASP.NET engine, and it does not delay directly from an console application. Is there a solution?

This is the way I'm calling the HTTP API:

 Dim strPostString As String = Convert.ToString(muriPostUrl) & mstrPostPath
    If mblnUseSecureConnection Then
        strPostString = Convert.ToString(muriSecurePostUrl) & mstrPostPath
    End If

    Dim strDataString As String = "username=" & mstrUsername
    strDataString += "&" & "password=" & mstrPassword
    strDataString += "&" & "originator=" & mstrOriginator
    strDataString += "&" & "recipients=" & mstrRecipients
    strDataString += "&" & "gateway=" & mstrGateway
    strDataString += "&" & "reference=" & mstrReference
    strDataString += "&" & "message=" & mstrMessage

    If mstrType <> String.Empty Then
        strDataString += "&" & "type=" & mstrType
    End If

    If mstrUDH <> String.Empty Then
        strDataString += "&" & "udh=" & mstrUDH
    End If

    If Not mdtDeliveryDate = Nothing Then
        Dim objDeliveryDate As New StringBuilder()
        objDeliveryDate.Append(mdtDeliveryDate.Year)
        objDeliveryDate.Append(Prefix(mdtDeliveryDate.Month.ToString(), 2))
        objDeliveryDate.Append(Prefix(mdtDeliveryDate.Day.ToString(), 2))
        objDeliveryDate.Append(Prefix(mdtDeliveryDate.Hour.ToString(), 2))
        objDeliveryDate.Append(Prefix(mdtDeliveryDate.Minute.ToString(), 2))
        objDeliveryDate.Append(Prefix(mdtDeliveryDate.Second.ToString(), 2))
        strDataString += "&" & "deliverydate=" & Convert.ToString(objDeliveryDate)
    End If

    Dim strReturnValue As String = ""

    Dim xmlReader As New XmlTextReader(String.Format("{0}?{1}", strPostString, strDataString))

    While xmlReader.Read()
        If xmlReader.NodeType = XmlNodeType.Element Then
            Select Case xmlReader.LocalName
                Case "recipients"
                    If True Then
                        mintSuccessCount = Integer.Parse(xmlReader.ReadString())
                        strReturnValue += "recipients : " & mintSuccessCount.ToString() & vbCr & vbLf
                        Exit Select
                    End If
                Case "success"
                    If True Then
                        mblnSuccess = Boolean.Parse(xmlReader.ReadString())
                        strReturnValue += "success : " & mblnSuccess.ToString() & vbCr & vbLf
                        Exit Select
                    End If
                Case "resultcode"
                    If True Then
                        mintResultCode = Integer.Parse(xmlReader.ReadString())
                        strReturnValue += "resultcode : " & mintResultCode.ToString() & vbCr & vbLf
                        Exit Select
                    End If
                Case "resultmessage"
                    If True Then
                        mstrResultMessage = xmlReader.ReadString()
                        strReturnValue += "resultmessage : " & mstrResultMessage & vbCr & vbLf
                        Exit Select
                    End If
            End Select
        End If
    End While

Also, when performing an HTTP request from ASP.NET, it does not appear in Fiddler, while the actual HTTP request happens. How can I track the HTTP fastback from within the ASP.NET engine?

I still don't know what the problem is, but I worked around it by doing the postback via an HttpWebRequest directly. I think the problem was somewhere in the while loop.

Heidelbergensis
  • 475
  • 2
  • 5
  • 18
  • 1
    Without providing code(Remove any sensitive information as login and passwords), info about the API etc it will be very hard to help you out.. A few code lines say more than 1000 words! – StefanE Oct 04 '11 at 08:50
  • I can also suggest that you'll try to use LINQ to XML, although not related to your problem it can simplify your code a lot. – the_drow Oct 04 '11 at 08:52
  • Would be interesting to see how the XML looks like after it been built – StefanE Oct 04 '11 at 09:22
  • 9
    @the_drow you are correct that [salutations and "thanks" are not necessary when posting on SO](http://meta.stackexchange.com/questions/2950/should-hi-thanks-taglines-and-salutations-be-removed-from-posts), but it's not necessary to point that out this rudely. – Pekka Oct 06 '11 at 10:22
  • 1
    @Pekka You might be right that it came off rude, but it's also the best way to explain to new comers why thanks and goodbyes is causing us to invest less time on his question. I will try to keep my tone down though. I don't mean to offend anyone. – the_drow Oct 10 '11 at 10:34

0 Answers0