我们有一个使用RIA服务的silverlight项目。我想在该项目和Web服务之间共享一些代码。我必须将代码保留在现在的位置,即我无法共享代码。
我认为好的是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服务项目选项来创建服务库。这创建了两个绑定在一起的项目(代理对象的代码gen)。两者都只是libs(1 Silverlight和1 .Net)
将任何RIA服务客户端库链接到Silverlight应用程序。然后将.web RIA项目链接到您的托管Web应用程序(用于标准的RIA使用)。您还可以将.web库作为.Net lib添加到Wcf服务中(不将其作为服务使用)。
如果您没有将主Silverlight项目创建为RIA服务项目,则需要将app.config文件中的设置移动到web.config文件中。如果您已具有服务支持设置,则只需复制数据库连接字符串。 Wcf项目只需要db连接字符串。
然后您应该能够使用服务器端RIA调用(不要忘记添加您自己的submitchanges调用,因为RIA在每批更新后在幕后执行此操作),或者只使用数据层(EF等)直接。
答案 1 :(得分:0)
没有完全完成,相继进一步。我现在面临的问题需要一个新问题。
上述问题的解决方案是取消选中“引用程序集中的重用类型”选项。添加服务引用时,单击高级按钮,您将获得“在引用的程序集中重用类型”选项。
这是因为我在我正在使用的两个项目之间共享一些代码,并且它试图在共享代码中“重用”我所拥有的对象。相反,我只是想让它为我创建代理对象而不是重用那些对象。
答案 2 :(得分:0)
是。有可能做到。
检查您的web.config是否与此相似
[?xml version =“1.0”?] [组态] [configSections] [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 =“假“/” [/ sectionGroup] [/ configSections]
[system.webServer] [validation validateIntegratedModeConfiguration =“false”/] [modules runAllManagedModulesForAllRequests =“true”] [add name =“DomainServiceModule”preCondition =“managedHandler”type =“System.ServiceModel.DomainServices.Hosting.DomainServiceHttpModule,System.ServiceModel.DomainServices.Hosting,Version = 4.0.0.0,Culture = neutral,PublicKeyToken = 31BF3856AD364E35”/] [/模块] [/system.webServer] [system.serviceModel] [domainServices] [端点] [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”/] [add name =“JSON”type =“Microsoft.ServiceModel.DomainServices.Hosting.JsonEndpointFactory,Microsoft.ServiceModel.DomainServices.Hosting,Version = 4.0.0.0,Culture = neutral,PublicKeyToken = 31bf3856ad364e35”/] [/端点] [/ domainServices] [serviceHostingEnvironment aspNetCompatibilityEnabled =“true”multipleSiteBindingsEnabled =“true”/] [/system.serviceModel]
[的ConnectionStrings] [add name =“ASPNETDBEntities1”connectionString =“metadata = res:// /Model1.csdl|res:// /Model1.ssdl|res://*/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 = b77a5c561934e089”/] [/ assemblies] [/ compilation] [/system.web] [/配置]