2010-09-29 120 views
4

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

我认为最好的是Web服务调用RIA服务。它将坐在同一台服务器上。

我去了我的网络服务项目,并添加了一个服务参考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 

回答

0

没有完全完成,得到了更多的进一步。我现在面临的问题现在需要一个新的问题。

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

这是因为我在我正在使用的两个项目之间共享一些代码,它试图在共享代码中“重复使用”我在我身边的对象。相反,我只是想让它为我创建代理对象,而不是重用这些对象。

1

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

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

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

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

+0

谢谢。我改变了这个问题。基本上我能够弄清楚,我必须选择“生成异步操作”选项,但实际上并没有生成任何有价值的代码。 App.config也是空的。 – peter 2010-09-30 20:01:07

0

是的。这是可能的。

  1. 创建库项目
  2. 添加的LINQ to实体模型
  3. 添加公共类DomainService1:LinqToEntitiesDomainService
  4. 检查你的web.config看起来像这样一个

    [XML版本= “1.0”?] [配置] [configSections] [sectionGroup名称= “system.serviceModel”] [段名= “domainServices” type =“System.ServiceModel.DomainServices.Hosting.DomainServicesSection,System.ServiceModel.DomainServices。托管,版本= 4.0.0.0,文化=中性公钥= 31BF3856AD364E35" allowDefinition的= “MachineToApplication” requirePermission = “假”/] [/ sectionGroup] [/ configSections]

    [system.webServer] [验证验证集成模式配置=“假”/] [模块runAllManagedModulesForAllRequests =“true”] [add name =“DomainServiceModule”preCondition =“managedHandler”type =“System.ServiceModel.DomainServices.Hosting.DomainServiceHttpModule,System.ServiceModel.DomainServices.Hosting,版本= 4.0.0.0,文化=中立,PublicKeyToken = 31BF3856AD364E35“/] [/ modules] [/system.webServer] [system.serviceModel] [domainServices] [endpoints] [add name =“OData”type =“System.ServiceModel.DomainServices.Hosting.ODataEndpointFactory,System.ServiceModel.DomainServices.Hosting.OData,Version = 4.0.0.0,Culture = neutral,PublicKeyToken = 31bf3856ad364e35“/] [add name =”soap“type =”Microsoft.ServiceModel.DomainServices.Hosting.SoapXmlEndpointFactory,Microsoft.ServiceModel.DomainServices.Hosting,Version = 4.0.0.0,Culture = neutral,PublicKeyToken = 31bf3856ad364e35“/] [/ code] [addpoints name =“JSON”type =“Microsoft.ServiceModel.DomainServices.Hosting.JsonEndpointFactory,Microsoft.ServiceModel.DomainServices.Hosting,Version = 4.0.0.0,Culture = neutral,PublicKeyToken = 31bf3856ad364e35”/] [/ endpoint] [/ domainServices] [serviceHostingEnvironment aspNetCompatibilityEnabled = “真” multipleSiteBindingsEnabled = “真”/] [/system.serviceModel]

    [的ConnectionStrings] [添加名称= “ASPNETDBEntities1” 的connectionString =“元数据= RES:// /Model1.csdl|res: // /Model1.ssdl|resources/Model1.msl;provider=System.Data.SqlClient;provider connection string = " data source = localhost; initial catalog = ASPNETDB; persist security info = True; user id = sa; password = yourpassword; multipleactiveresultsets = True; App = EntityFramework "“providerName =”System.Data.EntityClient“/] [/ connectionStrings] [system.web] [compilation debug =”true“] [assemblies] [add assembly =“System.Data.Entity,Version = 4.0.0.0,Culture = neutral,PublicKeyToken = b77a5c5619 34e089" /] [/组件] [/编译] [/system.web] [/配置]

    1. 做网页发布当地和测试服务的链接。 享受!
相关问题