0

I have created a client-based winforms application that parses a file and creates a Game object.

The plan is to have that client send the Game object to a webservice that is expecting that object type. Then on the server side, I would use Entity-Framework 4 to persist that information.

Essentially, that Game object is just a POCO/Model class.

How would I set things up on the server side so my application exposes a service and furthermore expects that type of object.

Thank you.

*snip* Scratch that, it wasn't what I needed.

1
  • 1
    I fail to see how this problem has to do with asp.net mvc. Maybe you should rephrase your question. Commented Jan 23, 2011 at 23:15

1 Answer 1

2

You can take advantage of MVC's ModelBinder functionality to automatically compose your input models from form or query data, e.g.:

public ActionResult Save(Game game)
{
    int id = game.Id;
    // Do work
    ...

And then on your client:

var request = (HttpWebRequest)WebRequest.Create("http://localhost/Game/Save");
string data = string.Format("Id={0}&Name={1}", HttpUtility.UrlEncode(game.Id), HttpUtility.UrlEncode(game.Name));
request.Method = "POST";
request.ContentLength = data.Length;
request.contentType= "application/x-www-form-urlencoded";

using (var writer = new StreamWriter(request.GetRequestStream()))
{
  writer.Write(data);
}

// Post the data.
var response = (HttpWebResponse)request.GetResponse();

This is all overkill, there are technologies that already exist such as WCF services, etc which will handle the proxy generation and communication for you. Have you considered them?

Sign up to request clarification or add additional context in comments.

1 Comment

I agree that WCF services would offer a very flexible solution. If the OP is still wanting to use MVC, then they could use a JsonValueProviderFactory - haacked.com/archive/2010/04/15/… which is registered by default in MVC3

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.