从 Silverlight 访问业务对象方法

发布于 2024-10-08 19:34:08 字数 513 浏览 4 评论 0原文

我是 Sliverlight 和 RIA 服务的新手,遇到了一些困难。

我有一个 Silverlight 应用程序,需要访问我们的 DAL 才能让我们的自定义对象填充 UI。我设置了 RIA 服务。在我的 Web 应用程序中,我添加了一个 DomainService,它调用 DAL 服务来取回数据。

我有一个单独的项目来容纳我们的业务对象,并且 DomainService 返回这些对象的列表。在业务对象中,我已将 Key 属性添加到 ID 属性中。

一切正常。我可以调用该服务,我可以获取对象列表。我可以在我的 Silverlight 应用程序中看到它们,并且可以看到对象的所有属性。

我唯一不明白的是如何访问这些方法。我的 Business 对象中有一些方法需要在 Silverlight 应用程序中访问,但该方法似乎并未公开。

有没有办法可以从类中访问这些方法?或者我是否必须在 DomainService 对象中编写一个包装器来为我调用此方法?我真的宁愿选择第一个。

任何帮助将不胜感激。这已经阻塞太久了。

I'm new to Sliverlight and RIA Services and I've hit a bit of a wall.

I have a Silverlight app that needs to access our DAL to get our custom objects to populate the UI. I set up the RIA service. In my web app, I have added a DomainService and it calls the DAL service to get the data back.

I have a separate project that houses our business objects and the DomainService returns this an list of these objects. In the business object, I have added the Key attribute to the ID property.

Everything is working fine. I can call the service, I can get the list of objects. I can see them in my Silverlight app and I can see all the properties of my objects.

The only thing I can't figure out is how to access the methods. I have a few methods in my Business object that I need to access in my Silverlight app, but it doesn't appear as though the method is exposed.

Is there a way that I can access these methods from the class? Or do I have to write a wrapper in my DomainService object that will call this method for me? I'd rather the first really.

Any help would be greatly appreciated. This has been blocking for far too long now.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

明天过后 2024-10-15 19:34:08

听起来你们很接近。

从您描述的方式来看,听起来业务对象类没有实例化。您需要将“存根”方法放入 Web 项目 (DomainService) 中,以允许 Silverlight 使用业务对象上的方法。

在您的 DomainService 类中:

using System.ServiceModel.DomainServices.Hosting; 
using System.ServiceModel.DomainServices.Server; 
using XYX.YourBusinessClassLibrary;  <-- need reference in web app

[EnableClientAccess()] 
public class linkdirectoryDS : DomainService 
{

    public IEnumerable<Category> GetCategories() 
    { 
        Category cat = new Category(); 
        return cat.Retrieve(); 
    } 
} 

关于 GetCategories 方法:

它必须是方法而不是属性。

必须返回以下之一:

  • 单个实体
  • IEnumerable,其中 T 是
    实体
  • IQueryable,其中 T 是
    实体

方法可以有任何名称、参数。

也许我只是描述了你不想做的事情......如果是这样,我深表歉意。

Sounds like you are pretty close.

From the way you describe it sounds like the business object classes aren't instantiated. You need to put "stub" methods into the web project (DomainService) that allows Silverlight to use the methods on the business object.

In your DomainService class:

using System.ServiceModel.DomainServices.Hosting; 
using System.ServiceModel.DomainServices.Server; 
using XYX.YourBusinessClassLibrary;  <-- need reference in web app

[EnableClientAccess()] 
public class linkdirectoryDS : DomainService 
{

    public IEnumerable<Category> GetCategories() 
    { 
        Category cat = new Category(); 
        return cat.Retrieve(); 
    } 
} 

About the GetCategories method:

It must be a method and not a property.

Must return one of:

  • A single entity
  • An IEnumerable where T is the
    entity
  • An IQueryable where T is the
    entity

The method can have any name, parameters.

Maybe I just described what you didn't want to do... if so I apologize.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文