Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Silverlight interaction with the Web Server

I never worked with Silverlight before, but I have the requirement to build a fairly dynamic/interactive form to fill out. That leaves me the choice between two technologies I have not much experience with: JavaScript/jQuery or Silverlight. (edit: The application is internal, I can safely assume Silverlight to be available)

At the end, I need to submit some data back to the server. I know that with a normal HTTP Form in ASP.net I can have a Button and an onClick Event - standard stuff. The JavaScript approach would include some DOM Manipulation to dynamically add/remove fields, but when I click on the button the current DOM gets served to my ASP.net Application and I process as normal. It is still a normal WebForms application.

But how would the interaction work with Silverlight? Can I have a Button in a Silverlight Application that essentially POSTs an HTTP Form? Or would I use a Web Service for this? It would be great if the Silverlight Application can get some data back from the server, so I guess it's a web service then?

like image 251
Michael Stum Avatar asked Jun 22 '26 02:06

Michael Stum


2 Answers

I suggest that you try out Silverlight to get a feel for how powerful that environment is. Personally I think that jQuery is nice, but you get a much more controlled and rich environment if you use Silverlight.

  1. Assuming you are using Visual Studio 2008 download Microsoft® Silverlight™ 3 Tools for Visual Studio 2008 SP1. This will enable you to create Silverlight projects in Visual Studio. You can also use Expression Blend to author Silverlight applications, but as long as you are comfortable writing XAML without a visual designer you might find Visual Studio a bit more mature from a developer standpoint.
  2. If you want to you can try Microsoft .NET RIA Services July 2009 Preview. It is a very powerful environment enabling your Silverlight application to seamlessly work with your data-model on your ASP.NET server. In particular there is very good integration with LINQ to SQL and the ADO.NET Entity Framework. However, if you are new to Silverlight you might find the learning curve a bit steep. You will have to load query operations in order to execute them asynchronously etc. Have a look at the Word document found at the download location to get you started.
  3. As others have suggested you can simply hide an HTML form in the web page hosting the Silverlight control and then use the HtmlPage object from within Silverlight to access the browser DOM to submit your form.
  4. If you want to do POST operations from within Silverlight without using a web service framework like .NET RIA Services or WCF you can use a WebClient or HttpWebRequest object. Silverlight 3 has two HTTP stacks and the default is to use the browser stack ensuring that browser cookies (e.g. forms authentication cookies) are used in your request.
  5. Your form has a complex interaction logic and I strongly suggest that you have a look at the MVVM pattern. In Silverlight you create a view-model containing all relevant data for the form. Relevant data not only include the values of the fields in the form but also information about which controls are enabled, selection information if that applies etc. You then data-bind the form (view) to the view-model and by implementing INotifyPropertyChanged in the view-model you get a complex interaction logic if not for free at least in a way that is reasonable easy to handle as a developer. The partial client-side classes generated for you in .NET RIA Services are particular good candidates for view-models making it straightforward to apply the MVVM pattern within that framework.
like image 184
Martin Liversage Avatar answered Jun 23 '26 16:06

Martin Liversage


It sounds as if you're seeking a web service with Silverlight. The framework is relatively robust and easy to implement - once you dive in it should be no problem to get your web service up and running quickly.

http://silverlight.net/getstarted/

While you could have your Silverlight app post the HTTP form that surrounds it, you need to make sure that this is the proper implementation path for your problem.

like image 38
JustLoren Avatar answered Jun 23 '26 16:06

JustLoren