Welcome

首页 / 软件开发 / Silverlight / Silverlight3系列(一)Silverlight配合WCF进行数据库操作

Silverlight3系列(一)Silverlight配合WCF进行数据库操作2010-11-12 博客园 virus1、环境配置

本文的Silverlight版本为Silverlight3,具体的配置过程可以参考:http://www.cnblogs.com/psunny/archive/2009/08/31/1556976.html或者http://www.cnblogs.com/wheeloffate/archive/2009/08/25/1553973.html

如果希望破解expression studio 3的话,可以在google中搜索【expression studio 3 破解】,也就是将下载的dll替换安装目录中的原文件,替换之前别忘了备份原文件,以防意外。

2、注意事项

2.1 跨域访问

跨域指的是当WCF的宿主和得宿主不在同一个域中的时候,默认是不可以访问的。这里的域指的是应用程序的域,详细介绍可以参看:.net中应用程序域的概念。

主要是指的wcf默认不支持跨域访问(当你在单独一个项目中),需要两个xml文件来声明wcf是可以跨域访问的。

下面的跨域支持来自:http://www.silverlightshow.net/items/WCF-Integration-in-Silverlight-2-Beta-1.aspx

Cross-Domain Support

If you want to enable your service to work cross-domain, there are two files you will want to concern yourself with:

crossdomain.xml

This file comes from back in the macromedia flash days. Since it has wide support on the internet, it makes sense for Silverlight to support it. You can read some documentation on this file format here.

One use supported by the specification is to specify domains which can access the service:

xml version="1.0"?>
DOCTYPE cross-domain-policy
SYSTEM "http://www.macromedia.com/xml/dtds/cross-domain-policy.dtd">
<cross-domain-policy>
<allow-access-from domain="www.yoursite.com" />
<allow-access-from domain="yoursite.com" />
<allow-access-from domain="*.moock.org" />
cross-domain-policy>

However, that detailed format is

not supported

by Silverlight. Instead, you must opt in to all domains if you want to use the crossdomain.xml approach. Such a policy file would look like this:

xml version="1.0"?>
DOCTYPE cross-domain-policy
SYSTEM "http://www.macromedia.com/xml/dtds/cross-domain-policy.dtd">
<cross-domain-policy>
<allow-access-from domain="*" />
cross-domain-policy>

However, since this format doesn"t cover all the scenarios that Silverlight developers are likely interested in (and flash developers too, most likely), Microsoft has provided another cross-domain file that is more flexible and currently Silverlight-specific: clientaccesspolicy.xml.