wcf ria服务方法返回

发布于 2024-10-25 23:14:27 字数 1005 浏览 2 评论 0原文

我有一个带有 wcf ria 服务的 Silverlight 站点,这只是一个测试。 该服务如下

[EnableClientAccess()]
    public class PersonService : DomainService
    {
        [Invoke]
        public string[] GetPersonNames()
        {
            return new string[] { "abc", "cba", "ddd", "ttt" };
        }

        [Invoke]
        public string GetName()
        {
            return "teste";
        }

        [Invoke]
        public string Test(string str)
        {
            return str;
        }
    }

我​​有一个 xaml 页面,我在其中调用该服务

SLRiaTest.Web.PersonContext person = new SLRiaTest.Web.PersonContext();

        public MainPage()
        {
            InitializeComponent();

            person.GetPersonNames(OnFinished,null);
        }

        private void OnFinished(InvokeOperation<string[]> obj)
        {
            var list = obj.Value;

        }

,但值始终为空,并且我在服务中的断点永远不会被命中。我在互联网上到处搜索,找不到任何可以告诉我做错了什么的东西,任何帮助都会很棒,我很绝望......我想我可以在没有实体框架的情况下使用 RIA 服务?

I have a Silverlight site with wcf ria services, this is just a test.
The service is as follow

[EnableClientAccess()]
    public class PersonService : DomainService
    {
        [Invoke]
        public string[] GetPersonNames()
        {
            return new string[] { "abc", "cba", "ddd", "ttt" };
        }

        [Invoke]
        public string GetName()
        {
            return "teste";
        }

        [Invoke]
        public string Test(string str)
        {
            return str;
        }
    }

I have a xaml page where I call the service

SLRiaTest.Web.PersonContext person = new SLRiaTest.Web.PersonContext();

        public MainPage()
        {
            InitializeComponent();

            person.GetPersonNames(OnFinished,null);
        }

        private void OnFinished(InvokeOperation<string[]> obj)
        {
            var list = obj.Value;

        }

but the Value is always null and the break point that I have in the serice never gets hit. I search the internet high and low and can't find anything that might tell me what I'm doing wrong, any help would be great, I'm desperate.... I suppose that I can use RIA service without entity framework right?

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

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

发布评论

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

评论(2

命比纸薄 2024-11-01 23:14:27

有关 RIA 服务中的线路呼叫的作用和作用的详细信息非常复杂。如果您想获得有关此处发生的情况的详细答案,您最好在 RIA 上提问。服务论坛

但是,您有点违背 RIA 服务的设计。如果要返回对象集合,则应使用 Query 而不是 Invoke。

[EnableClientAccess()]
public class PersonService : DomainService
{
    [Query]
    public IEnumerable<string> GetPersonNames()
    {
        return new string[] { "abc", "cba", "ddd", "ttt" };
    }
}

...

    public MainPage()
    {
        InitializeComponent();

        person.Load(person.GetPersonNamesQuery(), OnFinished, null);
    }

    private void OnFinished(LoadOperation<IEnumerable<string>> obj)
    {
        var list = obj.Value;
    }

我只是凭空想象了一下,所以可能会有一些小错误。但这是一般的想法。

The details on what does and does not work for calls across the wire in RIA Services are complex. If you want a detailed answer on what is going on here, you'll have better luck asking on the RIA Services forum

However, you're kind of going against the design of RIA Services. If you want to return a collection of objects, you should use Query instead of Invoke.

[EnableClientAccess()]
public class PersonService : DomainService
{
    [Query]
    public IEnumerable<string> GetPersonNames()
    {
        return new string[] { "abc", "cba", "ddd", "ttt" };
    }
}

...

    public MainPage()
    {
        InitializeComponent();

        person.Load(person.GetPersonNamesQuery(), OnFinished, null);
    }

    private void OnFinished(LoadOperation<IEnumerable<string>> obj)
    {
        var list = obj.Value;
    }

I just did that off the top of my head so might have some minor errors. But that's the general idea.

七婞 2024-11-01 23:14:27

我有一个你正在尝试的工作示例。您不需要更改您的域服务。确保您已安装 Visual Studio 2001 SP1,它还将 WCF RIA 更新到 SP1。

在您的 Silverlight 页面中,您可以按如下方式调用域服务:

public partial class MainPage : UserControl
    {
        private PersonContext _ctx = new PersonContext();

        public MainPage ()
        {
            InitializeComponent();
            Loaded += new RoutedEventHandler( MainPage_Loaded );
        }

        private void MainPage_Loaded ( object sender, RoutedEventArgs e )
        {
            _ctx.GetPersonNames( ( op ) =>
                {
                    if ( !op.HasError )
                    {
                        // The data here is your String[]
                        var data = op.Value;
                    }
                }, null );
        }
    }

I have a working example of what you are trying. You don't need to change your domain service. Ensure that you have installed Visual Studio 2001 SP1 which also updates WCF RIA to SP1.

In your Silverlight page you can call your domain service as follows:

public partial class MainPage : UserControl
    {
        private PersonContext _ctx = new PersonContext();

        public MainPage ()
        {
            InitializeComponent();
            Loaded += new RoutedEventHandler( MainPage_Loaded );
        }

        private void MainPage_Loaded ( object sender, RoutedEventArgs e )
        {
            _ctx.GetPersonNames( ( op ) =>
                {
                    if ( !op.HasError )
                    {
                        // The data here is your String[]
                        var data = op.Value;
                    }
                }, null );
        }
    }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文