开发者

How do I save data in Silverlight C#?

I want to make to make a site 开发者_如何学JAVAwhere a user can post to a string shown on front page. How can I do this?


From your question and ensuing clarification, it sounds like you do not want this text to be saved ber user/per machine - meaning that the data to be stored will need to be stored server-side rather than client side. Also, just to be complete, it is important to remember that Silverlight applications run 100% client-side.

How you save the data on the server is really up to you (you can write to a database for example.)

First, let's discuss setting the value. You in effect need to transmit data from the client (the silverlight application running in your browser) to the server. This is typically done by setting some kind of endpoint on the server to receive such information - usually a web service and corresponding method. Assuming Silverlight hosted in an ASP.Net page all within a Visual Studio project, you can just add sucha a service using the Visual Studio template for a "Silverlight-Enabled WCF Service." Create a "SetText" (or perhaps "AppendText") method that takes a String parameter. The body of the function should do the server-side storage...depending on the technology you're using.

As for retrieving the value, you have some options depending on your needs...if you're looking for "live" updates in the clients, you can either use Duplex communications with your web service (here) or perhaps polling. If you're interested only in having the value set when the application starts, you can either write it into the ASP.Net page as a startup parameter (here) for your Silverlight app, or use a web service call to get the value, which is also the solution to use if the value is to be updated based on user demand (hitting an Update/refresh button.) Remember that Web service calls in Silverlight are always Async, so you may have to set up some kind of "fetching data, please wait" user experience while this is happening.

Note that while I mentioned WCF Web Services above, other endpoint options are ceertainly available - REST services, ASMX services, etc. It all deepnds on your specific needs...

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜