【发布时间】:2010-08-24 18:58:33
【问题描述】:
我一直在寻找这个答案,我发现的只是这个link,但是当我尝试按照教程进行操作时,我失败了。我需要将我的 Silverlight 应用程序连接到数据库,只是为了显示来自特定表的信息。因为我不想为我的页面和我的 Silverlight 应用程序使用相同的 ORM,所以我创建了一个新的 WCF Web 服务项目,并在其中创建了我的 LINQ to SQL 类。
我测试了我的 WCF 服务,它工作正常,但不知何故,我的 Silverlight 应用程序无法访问它。我已经更改了 web.config 文件,现在它看起来如下。
我的 web.config
<?xml version="1.0"?> <configuration>
<connectionStrings>
<add name="bd_webportosConnectionString" connectionString="Data Source=BARNEY\DEV;Initial Catalog=bd_webportos;User ID=sa;Password=Stigeo_1_adm_1"
providerName="System.Data.SqlClient" /> </connectionStrings> <system.web>
<compilation debug="true" targetFramework="4.0" /> </system.web> <system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="basicHttpBindingConfig">
<security mode="TransportCredentialOnly">
<transport clientCredentialType="Ntlm"/>
</security>
</binding>
</basicHttpBinding>
</bindings>
<client>
<endpoint address="http://localhost:7298/DataToSilverlight.svc"
binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IService1"
contract="DataRetrieverReference.IService1" name="BasicHttpBinding_IService1" />
</client>
<behaviors>
<serviceBehaviors>
<behavior>
<!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->
<serviceMetadata httpGetEnabled="true"/>
<!-- To receive exception details in faults for debugging purposes, set the value below to true. Set to false before deployment to avoid disclosing exception information
-->
<serviceDebug includeExceptionDetailInFaults="false"/>
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" /> </system.serviceModel> <system.webServer>
<modules runAllManagedModulesForAllRequests="true"/> </system.webServer> </configuration>
我不知道如何解决这个问题。虽然我卡住了,但我试图继续前进,但在下一步我又卡住了,那就是将服务引用添加到我的 silverlight 应用程序。当我尝试按照它所说的去做时,会显示以下消息:
下载时出错 地址中的元数据。请 验证您是否输入了有效的 地址。
我通过 WCF 测试客户端测试了该服务,它工作正常,但我的 silverlight 应用程序无法访问它。我得到以下异常:
尝试制作时发生错误 对 URI 的请求 'http://localhost:7298/DataToSilverlight.svc'。 这可能是由于试图 跨域访问服务 没有适当的跨域策略 已到位,或已制定的政策 不适合 SOAP 服务。你可以 需要联系楼主 发布跨域的服务 策略文件,并确保它允许 要发送的与 SOAP 相关的 HTTP 标头。 此错误也可能是由于使用 Web 服务中的内部类型 不使用代理 InternalsVisibleToAttribute 属性。 请参阅内部异常 更多细节。
你们能帮我解决这个大问题,或者展示另一种方法来实现我想要的吗?
我最近还发现我的 crossdomain.xml 没有加载……但我不知道那是什么意思。
【问题讨论】:
-
您应该将标题更改为“如何将 Silverlight 连接到 WCF 服务?”因为这与数据库无关,而是客户端服务器通信。
标签: c# silverlight wcf web-services linq-to-sql