1. Roshan A's Avatar
    Hi All,

    Am new to windows phone development. Though i managed to learn some thing in past one week.I need a help how to establish a connection between the mobile and web part and storing data in web server.

    just consider am having a button an button event,in that am Capturing name and age, i need to save the data in database and send a response back to the mobile with the ID generated in Database. Can any one help me out, how to do in both mobile and web part.

    Any sample code or any related link will be very useful...
    04-17-2012 06:04 AM
  2. Dormage's Avatar
    It all depends what you have running on the server.
    If it's a web service that will handle the inserting to the database or you wan't to directly insert data from the phone?
    What kind of server do you have and whats running it?
    04-17-2012 07:11 AM
  3. Roshan A's Avatar
    It all depends what you have running on the server.
    If it's a web service that will handle the inserting to the database or you wan't to directly insert data from the phone?
    What kind of server do you have and whats running it?
    Its SQL server 2008. Am looking for request object kind of thing. But any ways connecting with web part could be useful.
    04-17-2012 07:47 AM
  4. rbrunner's Avatar
    As far as I know an app on WP7 can't directly talk to a SQL Server running on a server machine. You probably need a web service that takes in requests from your app, writes the data into the database and returns any id's generated by this.

    You may have a look at this:
    How to Connect Windows Phone 7 to a SQL Server? - App Hub Forums

    But anyway, your question is awfully general and very vague; it's hard to answer, and probably this forum is not a good place to ask anyway.
    Roshan A likes this.
    04-17-2012 09:06 AM
  5. PG2G's Avatar
    04-17-2012 09:16 AM
  6. abners's Avatar
    It all depends what you have running on the server.
    04-17-2012 10:17 AM
  7. Roshan A's Avatar
    Thanks for all your reply. Now am some what clear about establishing connection. Am using HTTPWebRequest for connection and able to hit webserver(i.e my local host).

    Now am not clear how to post some query while making the request?, and how to decode it in the Web part? and how to send the response back to the phone?,
    Can any one suggest me some ideas or any exact link could be helpful.
    04-23-2012 04:46 AM
  8. Dormage's Avatar
    Thanks for all your reply. Now am some what clear about establishing connection. Am using HTTPWebRequest for connection and able to hit webserver(i.e my local host).

    Now am not clear how to post some query while making the request?, and how to decode it in the Web part? and how to send the response back to the phone?,
    Can any one suggest me some ideas or any exact link could be helpful.
    Depends what your app does.
    If the querys are always of the same type you can program your server to only take the arguments of the query as a string and then execute the query with the given arguments.

    Executing querys directly from the phone is a security risk. If the app wan'ts to query your server it needs a password. If you hardcode the data base password in the app it is not safe.
    Maybe there are ways to do that safer but I hate databases and I'm not the right adress for these kind of questions :)
    04-23-2012 06:38 AM
  9. rbrunner's Avatar
    If you really only have a name and and an age to store, and to give back a generated id, and nothing else, you could indeed do a HTTPWebRequest, for example with name and age as URL parameters, like in

    GET /StoreIt.htm?name=Brunner&age=100

    and then give back the id as the data, with a MIME type of text, one line.

    But I really doubt whether this will be all you have to do. You will also want to browse through all the present names, maybe delete names, correct ages, and so on, right?

    For this, this simple HTTPWebRequest thing is not enough, you really need a webservice.

    Thing is, to pull this all through, you will not only have to learn about WP7 programming, but also about web services, about programming a server programm e.g. with ASP.NET MVC2, and accessing SQL server data e.g. with EF4.

    If you start with basically zero knowledge about this, you will probably have weeks of learning ahead of you. Maybe that's no problem for your project, I just think it would be good to be aware about that :)
    Roshan A likes this.
    04-23-2012 08:18 AM
  10. Roshan A's Avatar
    Thanks Brunner,
    Exactly am started with zero knowledge in this. Am just moving around these kind of stuff now.
    So we cannot use HTTPRequest for complex things like retrieving a list of items from the DB by passing an ID?
    Please provide me a link with some clear example for these whole internet process for windows phone.

    Thanks again.
    05-01-2012 04:55 AM
  11. thed's Avatar
    Thanks Brunner,
    Exactly am started with zero knowledge in this. Am just moving around these kind of stuff now.
    So we cannot use HTTPRequest for complex things like retrieving a list of items from the DB by passing an ID?
    Please provide me a link with some clear example for these whole internet process for windows phone.

    Thanks again.
    You could make a web request to a page that returns data from the database in a format like XML or JSON. But I agree with rbrunner. If you already have to run a server, then you might as well use a web service. It's a much better way to do things in the long run.

    I recommend that you go to msdn.microsoft.com and read about Web Services.
    05-01-2012 09:16 AM
  12. rbrunner's Avatar
    T
    Please provide me a link with some clear example for these whole internet process for windows phone.
    I never saw a full end-to-end-example of a WP7 app connection through a web service to a program running on a server accessing a SQL Server through EF4 or a similar technology, and I don't think that there is any.

    I think you will only find samples for parts of this whole solution, and at the end you will have to piece everything together yourself.

    I personally never would advice to a beginner to start with such a big, complicated and ambitious project, but with something much smaller and simpler.

    But anyway, if you really want to pull this through, a good strategy might be to learn all the technological pieces on their own, working backwards from to the SQL server to the phone:

    - Learn how to define databases, initialize them and access them through EF4. Write a (desktop) program doing essentially nothing more than working with some data.

    - Learn about web services. Write a server and a client, both again desktop programs, and let them exchange some fantasy data back and forth.

    - If the above things all work, switch the server from fantasy data to actual data accessed through EF4.

    - Write your app on the phone with some dummy / local data, as if the web service and the server would already run, learn about WP7 pages, controls, etc.

    - If that phone app works ok with dummy data, equip it a web client part and finally access the real data through your server.

    Good luck!
    Roshan A likes this.
    05-01-2012 10:11 AM
  13. CommonBlob's Avatar
    I have created an app that talks via a webservice to a SQL backend. It works very well, and using a webservice has the advantage of passing c# classes so you do not need to do casting and other messy things.

    The way I did it was create the app first, with dummy data (ensure you use databinding as this will help later on)

    Then I created the db structure.

    Then I created the stored procedures (this is my preferred way of doing it as I can change results on the SQL server rather than altering code)

    Then I created a webservice to get this data.

    Finally I linked them all up.

    I think Ive probably said what rbrunner said, but hope it helps ;)
    Roshan A likes this.
    05-01-2012 03:14 PM
  14. Roshan A's Avatar
    Thanks brunner and blob. Really am feeling lucky with your suggestion.From Now i ll start working reverse process.If i get struck any where, i ll come back here. Hope u guys help me out.

    Thanks,
    Roshan:)
    05-03-2012 05:13 AM
  15. dominiauk's Avatar
    Totally agree with Brunner and Blob.

    Web services really work well with mobile apps (just make sure you handle when the web service might be down in your app).

    Also rather than use EF4 if it's just simple reading and writing from a table I'd use something like PetaPoco. It's really simple and very fast, just google it.

    Good Luck
    05-03-2012 04:05 PM
LINK TO POST COPIED TO CLIPBOARD