我一直在寻找这个答案,所有我发现的是这link,但是当我试图按照教程,我失败了。我需要的是将我的Silverlight应用程序连接到数据库,以显示特定表中的信息。因为我不想为我的页面和我的silverlight应用使用相同的ORM,所以我创建了一个新的WCF webservice项目,并在其中创建了我的LINQ to SQL类。如何将我的Silverlight应用程序连接到WCF服务?
我测试了我的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服务?”因为这与数据库无关,而是与客户端服务器通信。 – 2010-08-24 19:04:44