Silverlight Interaction with the Web Server

I've never worked with Silverlight before, but I have a requirement to create a fairly dynamic / interactive form to fill out. This leaves me with a choice between two technologies that I have little experience with: JavaScript / jQuery or Silverlight. (edit: the app is internal, I can safely assume Silverlight will be available)

Eventually, I need to send 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 - the standard one. The JavaScript approach will include some DOM Manipulation to add / remove fields dynamically, but when I click on the button, the current DOM will be passed to my ASP.net application and I process as usual. This is still a regular WebForms application.

But how will interoperability work with Silverlight? Can I use a button in a Silverlight application that essentially launches an HTTP form? Or would I use a webservice for this? Would be great if the Silverlight application can return some data from the server, so I'm assuming it's a web service?

+2


source to share


9 replies


I suggest you give Silverlight a try to see how powerful this framework is. Personally, I think jQuery is good, but you are using a much more controllable and rich environment if you are using Silverlight.



  • This assumes you are using Visual Studio 2008 to download Microsoft® Silverlight ™ 3 for Visual Studio 2008 Service Pack 1 (SP1) . This will allow you to create Silverlight projects in Visual Studio. You can also use Expression Blend for Silverlight apps, but if you're comfortable writing XAML without a visual designer, you might find Visual Studio a little more mature from a developer standpoint.
  • If you want, you can try Microsoft .NET RIA Services July 2009 Preview . It is a very powerful framework for allowing your Silverlight application to run smoothly with your data model in your ASP.NET server. In particular, very good integration with LINQ to SQL and ADO.NET Entity Framework. However, if you're new to Silverlight, you might find the learning curve a little steep. You will have to load the request operations in order to execute them asynchronously, etc. Check out the Word document found at the download location to get started.
  • As other users suggested, you can simply hide the HTML form in the web page where the Silverlight control resides, and then use an object HtmlPage

    from Silverlight to access the browser DOM to submit your form.
  • If you want to perform POST operations from Silverlight without using a web service infrastructure like .NET RIA Services or WCF, you can use the WebClient

    or HttpWebRequest

    . Silverlight 3 has two HTTP stacks, and the default is the browser stack, ensuring that browser cookies (such as authentication cookies) are used in your request.
  • Your form has complex interaction logic and I highly recommend that you take a look at the MVVM pattern. In Silverlight, you create a view model that contains all the relevant data for a form. Relevant data includes not only the values ​​of the fields in the form, but also information about which controls are enabled, selection information if applicable, and so on. Then you bind data to the form (view) to the view model and implement INotifyPropertyChanged

    in the view model you get complex interaction logic, if not free, at least in a way that is reasonably easy to handle as a developer. The client-side partial classes generated for you in .NET RIA Services are particularly good candidates for viewmodels, making it easier to apply the MVVM pattern within this framework.
+2


source


It sounds like you are looking for a web service with Silverlight. The framework is relatively robust and easy to implement - once you dive into it, it shouldn't be a problem to get your web service up and running quickly.

http://silverlight.net/getstarted/



While your Silverlight application can host the HTTP form that surrounds it, you must ensure that this is the correct implementation path for your problem.

+2


source


I don't know how to write any JQuery, but I know Silverlight. I would say that if all you wanted was a Silverlight form it would be a little overkill and you could do something like JQuery.

However, since you know C #, you might be better off going with something closer to what you know in order to save time. If I was going to write this, I would go with Silverlight, ADO.Net Entity Model and RIA services. Using Silverlight Dataform, you could have a pretty dynamic form very quickly, and you could even just do validation to make sure your data is clean.

here check for posts by Brad Abrams.

+2


source


Here you can do it via Silverlight if you want to make the form post a button click.

In your aspx page that the Silverlight control is on, add a div, in my example I named it formDiv. The formData variable is your form that you created for posting.

        var doc = HtmlPage.Document;
        var el = doc.GetElementById("formDiv");
        el.SetProperty("innerHTML", formData);
        try
        {
            el.Children[0].Invoke("submit");
        }
        catch (Exception)
        {
            throw new LogicException("Error launching post");
        }

      

+2


source


Yes, you can have a button in your Silverlight application that will go to a server like an ASP.net Form. This is the same model that we can use .net framework members in Silverlight (albeit in a limited way).

+1


source


I can't believe everyone supports the Silverlight offering. Use jquery instead! You can create a fairly dynamic form and ensure that you have access to users across different platforms. I'm a web developer and I don't have Silverlight installed. I highly recommend jQuery!

+1


source


Silverlight is a powerful tool, but depending on the level of agility required, the path of least resistance might be to simply create an ASP.NET page and make it more dynamic with jQuery.

If you are using jQuery, you will learn Javascript and the jQuery library. If you are using Silverlight, you will learn WPF, WCF and how they interact with .NET server code.

If you have already created sites in ASP.NET you have 80% there with jQuery route. If you go the Silverlight route, I think the learning curve will be steeper.

If you go to the Silverlight option, Tim Heyer has some examples of communicating from Silverlight to Asp.net web services .

+1


source


Given that your project is internal, and given that you can ensure that Silverlight is installed, and given that all of your options can deliver what you want, the answer would seem to be preferable or itchy (which is what you personally want play).

You have not specified a project duration. With Silverlight, if you want an RIA-like result, you will most likely need Blend (which you didn't mention if you have access), later on you will have to spend a little time learning how to use Blend (how much effort depends on how rich your RIA might be).

The gap as I see it:

Web Services: If you are starting fresh you should use RIA or WCF unless you have a compelling reason to use a web service (e.g. it already exists, you have no choice, etc.).

WCF: Replaces webservices, however you will often have to build most of the plumbing yourself.

RIA: Designed to implement data services for Silverlight (expected to be included in ASPX in the future). RIA Services is not yet in beta. Do you have to keep in mind that there may be violations and the application will not work until you can resolve these changes, impacting your company too much?

You left ASPX without explanation. It may be that your view of dynamics differs from many. I have to wonder if ASPX and AJAX (if you even need AJAX) would help solve your problem better.

jQuery can certainly do the job, so the ball is in your yard. How much time do you have and what do you want to know and how dynamic do you really want / need to be?

Addressing some other points of this protector. Learning Silverlight doesn't have to be that cool. If you're not into animation, the Blend IDE is probably the most time consuming part. In fact, if you are mainly using VS for coding, then Blend will be mainly used for layout. For a simple RIA, you can even skip Blend (but I wouldn't recommend doing that).

Finally, you might think about working on some specs (behavior / design / db) and then ask what people will use.

+1


source


In a nutshell, it consumes web services through the Silverlight WCF client implementation, and Silverlight offers several ways to access web services.

silverlight.net video is great too, there are some examples.

+1


source







All Articles