c# - 在没有 silverlight 项目的情况下使用 RIA 服务

标签 c# .net silverlight ria

我们有一个使用 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

最佳答案

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

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

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

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

关于c# - 在没有 silverlight 项目的情况下使用 RIA 服务,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3825641/

相关文章:

c# - Silverlight - 是否可以在后台线程上创建 UI 元素?

c++ - Silverlight 客户端可以与 C++ 服务器通信吗?

javascript - 将一个有点复杂的 javascript 函数的值返回给 silverlight 用户控件

c# - MiniProfiler 不工作

c# - 这是 BindingList 应该工作的方式吗?

c# - 使用 fiddler core 修改响应

c# - 在字符串列表中查找与输入字符串最接近的匹配项

c# - 为什么我的 winforms 应用程序中的自动版本控制没有增加?

c# - 在 C# 中处理大文件时出现内存不足异常

c# - 使用 DllImport 调用 C++ 函数