954,574 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

ASP.NET and Java ME

Hi!
I'm trying to send data from a mobile application written in Java ME, to an ASP.NET website connected to an SQL server. I tried to open an httpconnection output stream in the Java ME application, and send the data in a POST to the website. The problem is I don't know how to accept data on the website. I found code online that I tried to modify to suit my application, but I feel I'm waaaay off. Could anyone give me some pointers on how to go about this?

Protected Sub Button1_Click(sender As Object, e As System.EventArgs) Handles Button1.Click

        Dim str As Stream
        Dim strLen As Integer
        Dim strRead As Integer


        'Request input stream from the poster
        str = Request.InputStream


        'Get the length of incoming string
        While (strLen = 0)
            strLen = str.Length
        End While

        'make a Byte array the size of the stream
        Dim strArr(strLen) As Byte


        'read the stream into the array
        strRead = str.Read(strArr, 0, strLen)

        Label1.Text = strArr.ToString()


    End Sub
Natique
Light Poster
28 posts since Feb 2008
Reputation Points: 11
Solved Threads: 0
 

Why not save the data in the database and display that data on the ASP.Net page? You can then have an AJAX web service that loops to see if there is new data in the database to display.

stbuchok
Master Poster
730 posts since May 2011
Reputation Points: 120
Solved Threads: 93
 

You mean send the data directly from the mobile phone to the SQL server? I didn't look into that because in other forums I saw people asking about that, and everyone would reply, you'll need to add a webpage with that. Is it doable?

Natique
Light Poster
28 posts since Feb 2008
Reputation Points: 11
Solved Threads: 0
 

Just create a web service. the web service will be able to be used by any language that supports web services and any device that has an internet connection. You will be able to send data through to the database and use another web service to grab the data.

stbuchok
Master Poster
730 posts since May 2011
Reputation Points: 120
Solved Threads: 93
 

Ok I'm sorry, but I'm new to this and I'm really confused. I've already written the Java ME application that sends data using an HTTP post, and I've already made the website using ASP.NET. So I'd prefer not to get into web services. Forget the SQL server, where in my ASP.NET application should I accept the data coming from the mobile phone? It doesn't really make sense in the page_load event? Because that doesn't seem right to me.

Natique
Light Poster
28 posts since Feb 2008
Reputation Points: 11
Solved Threads: 0
 

In case someone ever has the same problem, turns out the above code is pretty much right. I added these lines of code to make it work better:

' the stream will be ASCII encoded'
         Dim ascii As ASCIIEncoding = New ASCIIEncoding

        'Get ASCII into reg. string here'
         strmContent = ascii.GetString(strArr)
         Label1.Text = strArr.ToString()

        'write the received data to a text file'
        Dim FILE_NAME As String = "C:\\NP\\received.txt"
        Dim objWriter As New System.IO.StreamWriter(FILE_NAME, True)
        objWriter.WriteLine(strmContent)
        objWriter.WriteLine()
        objWriter.Close()


Most of the code I used came from this forum discussion, if you'd like to look at it: http://bytes.com/topic/asp-net/answers/327711-receive-https-post
And the code should be placed in the ASP.NET page-load event.

Natique
Light Poster
28 posts since Feb 2008
Reputation Points: 11
Solved Threads: 0
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: