2010-09-29 117 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. 做網頁發佈當地和測試服務的鏈接。 享受!
相關問題