码迷,mamicode.com
首页 > 其他好文 > 详细

调用Ria Service中方法的各种方式

时间:2014-10-29 18:39:32      阅读:214      评论:0      收藏:0      [点我收藏+]

标签:style   blog   http   io   color   os   ar   使用   for   

前端界面后台:

bubuko.com,布布扣
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.ServiceModel.DomainServices.Client;
using System.Collections.ObjectModel;

using SilverlightRiaService.Web;


namespace SilverlightRiaService
{
    public partial class MainPage : UserControl
    {
        public MainPage()
        {
            InitializeComponent();

            ServiceClass sc = new ServiceClass();

            sc.GetUnitType(1, "admin", DateTime.Now.AddDays(-20), DateTime.Now, o =>
            {
                if (o.HasError)
                {
                    MessageBox.Show("error");
                }
                else
                {
                    string strvalue = o.Value;
                    MessageBox.Show("直接调" + strvalue);
                }
            }, null);
            sc.InvokeOperation("GetUnitType", typeof(IEnumerable<string>),
                new Dictionary<string, object> { { "unit", 1 }, { "systype", "admin" }, { "startTime", DateTime.Now.AddDays(-20) }, { "endTime", DateTime.Now } }, true, evv =>
                {
                    if (!evv.HasError)
                    {
                        var sd = evv.Value;
                        MessageBox.Show("Invoke" + sd.ToString());
                    }
                }, null);

            /*
             在Silverlight中创建数据源集合可以使用内建的ObservableCollection类,
             因为ObservableCollection类既实现了INotifyPropertyChanged接口,又实现了INotifyCollectionChanged接口。
             使用ObservableCollection类不但可以实现Add、Remove、Clear和Insert操作,还可以触发PropertyChanged事件。
             */

            ObservableCollection<Student> stulist = new ObservableCollection<Student>();
            sc.GetStudentByName("叶薇", ye =>
            {
                if (!ye.HasError)
                {
                    stulist = (ObservableCollection<Student>)ye.Value;
                }
            }, null);
            sc.InvokeOperation("GetStudentByName", typeof(ObservableCollection<Student>),
                new Dictionary<string, object> { { "name", "叶朔" } }, true, shuo =>
                {
                    if (!shuo.HasError)
                    {
                        stulist = new ObservableCollection<Student>(shuo.Value as IEnumerable<Student>);
                        List<Student> sdstulist = new List<Student>(shuo.Value as IEnumerable<Student>);
                    }
                }, null);
        }
    }
}
View Code

Ria Service方法:

bubuko.com,布布扣
namespace SilverlightRiaService.Web
{
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.ServiceModel;
    using System.ServiceModel.DomainServices.Hosting;
    using System.ServiceModel.DomainServices.Server;

    [EnableClientAccess()]
    public class ServiceClass : DomainService
    {
        public string GetUnitType(int unit, string systype, DateTime startTime, DateTime endTime)
        {
            return unit + systype + startTime + endTime;
        }

        public IEnumerable<Student> GetStudentByName(string name)
        {
            List<Student> list = new List<Student>();
            list.Add(new Student()
            {
                StudentName = name,
                Sex = ""
            });
            return list;
        }

    }
}
View Code

Web Config 添加:

bubuko.com,布布扣
<?xml version="1.0" encoding="utf-8"?>

<!--
  有关如何配置 ASP.NET 应用程序的详细信息,请访问
  http://go.microsoft.com/fwlink/?LinkId=169433
  -->

<configuration>
  <system.webServer>
    <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"/>
    </modules>
    <validation validateIntegratedModeConfiguration="false"/>
  </system.webServer>

  <system.web>
    <httpModules>
      <add name="DomainServiceModule" type="System.ServiceModel.DomainServices.Hosting.DomainServiceHttpModule, System.ServiceModel.DomainServices.Hosting, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
    </httpModules>
    <compilation debug="true" targetFramework="4.5"/>
    <httpRuntime targetFramework="4.5" />
  </system.web>
  <system.serviceModel>
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true"/>
  </system.serviceModel>
</configuration>
View Code

 

调用Ria Service中方法的各种方式

标签:style   blog   http   io   color   os   ar   使用   for   

原文地址:http://www.cnblogs.com/yisheng/p/4060140.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!