怎样的Silverlight从MySQL获取其数据 [英] How to have silverlight get its data from MySQL

查看:191
本文介绍了怎样的Silverlight从MySQL获取其数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经写在Silverlight小的Hello World的测试应用程序,我想举办一个Linux / Apache2的服务器上。我希望数据来自MySQL的(或其他一些Linux兼容分贝),这样我可以数据绑定到的东西,在分贝。

I've written a small hello world test app in Silverlight which i want to host on a Linux/Apache2 server. I want the data to come from MySQL (or some other linux compatible db) so that I can databind to things in the db.

我已经成功地得到它的工作使用的MySQL Connector / .NET

I've managed to get it working by using the MySQL Connector/.NET:

MySqlConnection conn = new MySqlConnection("Server=the.server.com;Database=theDb;User=myUser;Password=myPassword;");
conn.Open();
MySqlCommand command = new MySqlCommand("SELECT * FROM test;", conn);
using (MySqlDataReader reader = command.ExecuteReader())
{
     StringBuilder sb = new StringBuilder();
     while (reader.Read())
     {
         sb.AppendLine(reader.GetString("myColumn"));
     }
     this.txtResults.Text = sb.ToString();
}

这工作正常,如果我给已发布的ClickOnce应用程序完全信任(或至少SocketPermission的)和本地运行

This works fine if I give the published ClickOnce app full trust (or at least SocketPermission) and run it locally.

我想这在服务器上运行,我不能得到它的工作,始终结束与许可例外(SocketPermission的是不允许的)。

I want this to run on the server and I can't get it to work, always ending up with permission exception (SocketPermission is not allowed).

数据库托管在同一台服务器的Silverlight应用程序。如果有什么差别。

The database is hosted on the same server as the silverlight app if that makes any difference.

修改 好吧,我现在明白为什么这是一个坏主意,有在客户端应用程序(显然)数据库凭据。人们是如何做到这一点呢?你如何确保代理web服务,以便转发数据,并从客户端/ DB以安全的方式?是否有任何的例子在那里在网络上?

EDIT Ok, I now understand why it's a bad idea to have db credentials in the client app (obviously). How do people do this then? How do you secure the proxy web service so that it relays data to and from the client/db in a secure way? Are there any examples out there on the web?

当然,我不能谁愿意使用一个数据库来提供动力Silverlight应用程序的第一人?

Surely, I cannot be the first person who'd like to use a database to power a silverlight application?

推荐答案

做你想做的最简单的方法(通过您的编辑看了现在:))将以公开,可消费的服务。微软正在真正推动现在的模式是公开WCF服务,但事实是,你的Silverlight客户端可以使用WCF消耗了大量不同类型的服务的。

The easiest way to do what you want (having read through your edits now :)) will be to expose services that can be consumed. The pattern that Microsoft is REALLY pushing right now is to expose WCF services, but the truth is that your Silverlight client can use WCF to consume a lot of different types of services.

这可能是最简单的,你现在做的是将Web服务器或者一个PHP REST服务上使用.NET服务,然后在该服务点你的Silverlight应用程序。通过这样做,你不仅保护来自人们通过它监听你的数据库,但更重要的是,你是限制什么人可以做你的数据库。如果您的数据应该是只读的,和你的服务的合同只允许读取操作,你设置。或者,您的服务可能协商凭据会议,再次,建立了通过WCF。

What may be easiest for you to do right now would be to use a .NET service on a web server or maybe a PHP REST service, and then point your Silverlight app at that service. By doing so, you're protecting your database not only from people snooping through it, but more importantly, you're restricting what people can do to your database. If your data is supposed to be read-only, and your service's contract only allows reading operations, you're set. Alternatively, your service may negotiate sessions with credentials, again, set up through WCF.

的WCF可以是一个仅客户机,服务器,或者仅客户端 - 服务器连接器平台。你选择什么会影响你写的code,但是这一切都将是独立于数据库。您的code可以这样构成,它是一个一对一的映射到数据库表,也可以是更抽象的(你可以设置重新present全逻辑视图类,如果你选择)。

WCF can be a client-only, server-only, or client-server connector platform. What you choose will affect the code you write, but it's all going to be independent of your database. Your code can be structured such that it's a one-to-one mapping to your database table, or it can be far more abstract (you can set up classes that represent full logical views if you choose).

这篇关于怎样的Silverlight从MySQL获取其数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆