【问题标题】:Consuming RIA services without a silverlight project在没有 Silverlight 项目的情况下使用 RIA 服务
【发布时间】:2012-02-01 22:09:07
【问题描述】:

我们有一个使用 RIA 服务的 silverlight 项目。我想在该项目和 Web 服务之间共享一些代码。我必须将代码留在现在的位置,即我无法共享代码。

我认为好的是让 Web 服务调用 RIA 服务。它将位于同一台服务器上。

我去了我的 Web 服务项目,并添加了对 ria 服务的服务引用。我点击了高级并勾选了“生成异步操作”选项。

我认为一切都很好,但我收到了一些警告。它生成的客户端代码缺少与异步调用相关的任何实际代码,并且 app.config 也是空的。以下是警告,

Warning 2   Custom tool warning: Cannot import wsdl:binding
Detail: There was an error importing a wsdl:portType that the wsdl:binding is dependent on.
XPath to wsdl:portType: //wsdl:definitions[@targetNamespace='http://tempuri.org/']/wsdl:portType[@name='CarServiceSoap']
XPath to Error Source: //wsdl:definitions[@targetNamespace='http://tempuri.org/']/wsdl:binding[@name='BasicHttpBinding_CarServiceSoap'] C:\Develop\DotNet\Trunk\Applications\WcfServices\CarTransmitter\CarTransmitter.Core\Service References\CarService\Reference.svcmap  1   1   CarTransmitter.Core

Warning 3   Custom tool warning: Cannot import wsdl:port
Detail: There was an error importing a wsdl:binding that the wsdl:port is dependent on.
XPath to wsdl:binding: //wsdl:definitions[@targetNamespace='http://tempuri.org/']/wsdl:binding[@name='BasicHttpBinding_CarServiceSoap']
XPath to Error Source: //wsdl:definitions[@targetNamespace='http://tempuri.org/']/wsdl:service[@name='CarService']/wsdl:port[@name='BasicHttpBinding_CarServiceSoap']   C:\Develop\DotNet\Trunk\Applications\WcfServices\CarTransmitter\CarTransmitter.Core\Service References\CarService\Reference.svcmap  1   1   CarTransmitter.Core

Warning 1   Custom tool warning: Cannot import wsdl:portType
Detail: An exception was thrown while running a WSDL import extension: System.ServiceModel.Description.DataContractSerializerMessageContractImporter
Error: Referenced type 'CarData.Organisation, CarData, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' with data contract name 'Organisation' in namespace 'http://schemas.datacontract.org/2004/07/CarData' cannot be used since it does not match imported DataContract. Need to exclude this type from referenced types.
XPath to Error Source: //wsdl:definitions[@targetNamespace='http://tempuri.org/']/wsdl:portType[@name='CarServiceSoap'] C:\Develop\DotNet\Trunk\Applications\WcfServices\CarTransmitter\CarTransmitter.Core\Service References\CarService\Reference.svcmap  1   1   CarTransmitter.Core

【问题讨论】:

    标签: c# .net silverlight ria


    【解决方案1】:

    使用 RIA 服务项目选项来创建您的服务库。这会创建 2 个绑定在一起的项目(用于代理对象的代码生成)。两者实际上都只是库(1 个 Silverlight 和 1 个 .Net)

    将任何 RIA 服务客户端库链接到您的 Silverlight 应用程序。然后将 .web RIA 项目链接到您的托管 Web 应用程序(供标准 RIA 使用)。您还可以将 .web 库作为 .Net 库添加到您的 Wcf 服务中(不要将其作为服务使用)。

    如果您没有将主 Silverlight 项目创建为 RIA 服务项目,则需要将设置从 app.config 文件移动到 web.config 文件。如果您已经拥有服务支持设置,则只需复制 db 连接字符串。 Wcf 项目只需要 db 连接字符串。

    然后您应该能够使用服务器端 RIA 调用(不要忘记添加您自己的 submitchanges 调用,因为 RIA 在每批更新的后台执行一次),或者只使用数据层(EF等)直接。

    【讨论】:

    • 谢谢。我已经改变了问题。基本上我能够确定我必须选择“生成异步操作”选项,但它实际上并没有生成任何有价值的代码。 App.config 也是空的。
    【解决方案2】:

    还没有完全完成,还有很多。我现在遇到的问题需要提出一个新问题。

    上述问题的解决方案是取消勾选“在引用的程序集中重用类型”选项。添加服务引用时,单击高级按钮并获得“在引用的程序集中重用类型”选项。

    这是因为我正在使用的两个项目之间共享一些代码,并且它试图“重用”我在共享代码中拥有的对象。相反,我只是希望它为我创建代理对象,而不是重用这些对象。

    【讨论】:

      【解决方案3】:

      是的。是可以的。

      1. 创建库项目
      2. 将 LINQ 添加到实体模型
      3. 添加公共类 DomainService1 : LinqToEntitiesDomainService
      4. 检查你的 web.config 是否像这样

        [?xml 版本=“1.0”?] [配置] [配置部分] [sectionGroup name="system.serviceModel"] [section name="domainServices" type="System.ServiceModel.DomainServices.Hosting.DomainServicesSection, System.ServiceModel.DomainServices.Hosting, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" allowDefinition="MachineToApplication" requirePermission="错误的” /] [/节组] [/configSections]

        [system.webServer] [验证 validateIntegratedModeConfiguration="false" /] [模块 runAllManagedModulesForAllRequests="true"] [添加名称="DomainServiceModule" preCondition="managedHandler" type="System.ServiceModel.DomainServices.Hosting.DomainServiceHttpModule, System.ServiceModel.DomainServices.Hosting, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" /] [/模块] [/system.web服务器] [系统.服务模型] [域服务] [端点] [add name="OData" type="System.ServiceModel.DomainServices.Hosting.ODataEndpointFactory, System.ServiceModel.DomainServices.Hosting.OData, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" /] [添加名称=“soap”类型=“Microsoft.ServiceModel.DomainServices.Hosting.SoapXmlEndpointFactory,Microsoft.ServiceModel.DomainServices.Hosting,版本=4.0.0.0,文化=中性,PublicKeyToken=31bf3856ad364e35”/] [添加名称=“JSON”类型=“Microsoft.ServiceModel.DomainServices.Hosting.JsonEndpointFactory,Microsoft.ServiceModel.DomainServices.Hosting,版本=4.0.0.0,文化=中性,PublicKeyToken=31bf3856ad364e35”/] [/端点] [/域服务] [serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" /] [/system.serviceModel]

        [连接字符串] [添加 name="ASPNETDBEntities1" connectionString="metadata=res:///Model1.csdl|res:///Model1.ssdl|res://*/Model1.msl;provider=System .Data.SqlClient;provider 连接字符串=“数据源=localhost;初始目录=ASPNETDB;持久安全信息=True;用户ID=sa;密码=你的密码;multipleactiveresultsets=True;App=EntityFramework"" providerName="System.Data .EntityClient" /][/connectionStrings] [系统.web] [编译调试="true"][程序集][添加程序集="System.Data.Entity, 版本=4.0.0.0, 文化=中性, PublicKeyToken=b77a5c561934e089" /][/程序集][/编译] [/system.web] [/配置]

        1. 在本地做WEB Publishing并测试服务链接。 尽情享受吧!

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2011-09-25
        • 2014-08-06
        • 1970-01-01
        • 2011-03-06
        • 2019-03-04
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多