前端界面后台:

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(, "admin", DateTime.Now.AddDays(-), 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", }, { "systype", "admin" }, { "startTime", DateTime.Now.AddDays(-) }, { "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);
}
}
}

Ria Service方法:

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;
} }
}

Web Config 添加:

<?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>

调用Ria Service中方法的各种方式的更多相关文章

  1. android 中activity调用远程service中的方法之 aidl的使用

    服务端:只有服务,没有界面 1.编写interface文件,复制到 .aidl 文件中,并去掉其中的public 等修饰符.系统会自动在gen目录下生成对应的java文件  (对应本地调用中的接口文件 ...

  2. android 中activity调用本地service中的方法。

    1.自定义一个接口,暴露服务中的方法 public interface IService {    /**服务中对外暴露的方法 */    void methodInService();} 2.自定一 ...

  3. jQuery Ajax 方法调用 Asp.Net WebService 以及调用aspx.cs中方法的详细例子

    一.jQuery Ajax 方法调用 Asp.Net WebService (引自Terry Feng) Html文件 <!DOCTYPE html PUBLIC "-//W3C//D ...

  4. C#实现调用Java类中方法

    基本思路: 用C#实现调用Java编写的类中的方法:重点是将Java编写的程序打包成Jar,然后使用开源工具IKVM将其转化成DLL控件,在.NET环境下调用. 分为以下步骤: 1.下载JDK6(注: ...

  5. C#反射调用程序集类中方法

    建立类 class OperatorClass { /// <summary> /// 加法 /// </summary> /// <param name="x ...

  6. C#调用Dll文件中方法的简单应用

    参考:http://www.cnblogs.com/Asuphy/p/4206623.html 直接看代码,最简单的引入,只需要3步: using System; using System.Colle ...

  7. C#A类派生类强转基类IL居然还是可以调用派生类中方法的例子

    大家都知道在C#中,如果B类继承自A类,如果一个对象是B类型的但是转换为A类型之后,这个对象是无法在调用属于B类型的方法的,如下例子: 基类A: public class A { } 派生类B: pu ...

  8. 实现php Curl 调用不同项目中方法

    之前为了实现跨项目调用方法,遇到的一些问题和解决方法总结. 话不多说,直接复制代码先跑了再说! jq代码. $.ajax({ type: "post", dataType: &qu ...

  9. 通过反射对任意class类中方法赋值的方式

    import org.apache.commons.lang3.StringUtils;import org.slf4j.Logger;import org.slf4j.LoggerFactory;i ...

随机推荐

  1. 初试微信小程序

    2016年11月3日,微信小程序终于公测了,大家可以正式开发了.早在这之前,应公司要求,和同事就早早的试了一下微信小程序的开发,特此记录一下: 微信官方小程序文档:https://mp.weixin. ...

  2. JavaScript中this和$(this)之间的区别以及extend的使用

    jQuery中this和$(this)之间的区别: this返回的是当前对象的html对象,而$(this)返回的是当前对象的jQuery对象 举个正确的Demo实例: $("#textbo ...

  3. Java数据结构和算法之哈希表

    五.哈希表 一般的线性表.树中,记录在结构中的相对位置是随机的即和记录的关键字之间不存在确定的关系,在结构中查找记录时需进行一系列和关键字的比较.这一类查找方法建立在“比较”的基础上,查找的效率与比较 ...

  4. Centos7.2 Systemd 方式编译 Mysql5.7.11

    导读 MySQL 5.7 版本的发布,也就是说从现在开始5.7已经可以在生产环境中使用,有任何问题官方都将立刻修复. MySQL 5.7主要特性: 原生支持Systemd 更好的性能:对于多核CPU. ...

  5. Struts2 Action中的方法命名不要以get开头

    偶然发现,在调用一个action中的某个方法时,会自动调用另一个无关的方法,找了好久,最后发现是方法命名的问题,方法命名以get开头,action会自动调用!所以,以后再写action中的方法时尽量不 ...

  6. Apache服务器配置技巧

    1.如何设置请求等待时间 在httpd.conf里面设置: TimeOut n 其中n为整数,单位是秒. 设置这个TimeOut适用于三种情况: 2.如何接收一个get请求的总时间 接收一个post和 ...

  7. 论文笔记之:Co-saliency Detection via A Self-paced Multiple-instance Learning Framework

    Co-saliency Detection via A Self-paced Multiple-instance Learning Framework  T-PAMI  2016  摘要:Co-sal ...

  8. MongoDB 备份(mongodump)恢复(mongorerstore) 导出 (Mongoexport) 导入( Mongoimport)

    MongoDB 备份(mongodump) 在Mongodb中我们使用mongodump命令来备份MongoDB数据.该命令可以导出所有数据到指定目录中. mongodump命令可以通过参数指定导出的 ...

  9. 五、Spring ——单元测试

    1.JUnit4 JUnit测试用例的完整生命周期要经历一下阶段:类级初始化资源处理,方法级初始化资源处理.执行测试用例中的方法.方法级销毁资源处理.类级销毁资源处理. 测试方法 @Test 初始化 ...

  10. 【dom4j】解析xml为map

    dom4j解析xml文件 <?xml version="1.0" encoding="utf-8"?> <workflows> < ...