views:

115

answers:

4

I have a mobile application which I want to call a http post to pass a binary string and write it to a SQL Server. Can you please give me some examples of code in setting up a http post server (Server side code) to accept 2 values (brinary string & DeviveID string).

Any help, advice or links welcome....

A: 

I don't know the iPhone side, but from the C# side, you could either do it via HTTP GET variables (e.g. http://www.example.com/?string=foo&devive=bar) and handle your SQL in there.

You could also run a small program that has a listening Socket or TcpListener on whatever port you want, and then have a BeginRead() method active waiting for input from the iPhone app. Once the BeginRead() returns with some data, you could then handle your SQL.

nasufara
A: 

You could create a WCF REST service for this (look up the WCF REST Starter Kit), but as a quick-and-dirty solution you could do something much simpler: Just create an ASP.NET page that processes incoming POST data in its Page_Load handler.

If your POST format is the same one used by browsers (var1=123&var2=456), you can just use Request.Form["var1"] on the page. See http://forums.asp.net/t/1464546.aspx

If your POST format is different (e.g. XML), use Request.InputStream. See http://schlueters.de/blog/archives/31-Manually-processing-HTTP-POST-data-in-an-aspx.html

Eugene Osovetsky
A: 

You could setup a Web Method on the web server to handle the requests from the iPhone app. Then you just send the data as a normal HTTP POST and the web method would handle the data, and call the SQL Server stored procedure.

mrdenny
A: 

You should be able to check the Request object to see if the data was posted and then perform your call to SQL Server.

For example:

Request.Params.Get( "sampleParam" )

will return the value of a sampleParam. As long as the posting application, page, or device posted the data you are expecting you will be able to get to it.

Miyagi Coder