前端界面后台:

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. Android 学习第3课,小例子

    package temperature.convert; import java.util.Scanner; public class Converter { public static void m ...

  2. ubuntu14.04 安装 bcm43142无线网卡

    thinkpad e430c 在安装ubuntu14.04时无法识别无线网卡 用命令lspci 查看无线网卡类型 然后下载对应的无线网卡驱动. 之后,使用下列命令安装,即可搜索无线热点了: sudo ...

  3. Scalding初探之二:动手来做做小实验

    输入文件 Scalding既可以处理HDFS上的数据,也可以很方便地在本地运行处理一些test case便于debug,Source有好多种 1 TextLine(filename) TextLine ...

  4. C++ 中的形参与返回值

    函数调用时,形参对象和返回对象均采用引用方式进行(临时对象作为中介),当一个对象作为参数(非引用)被函数调用时,该对象会通过复制构造函数获得一个临时对象,该临时对象以引用方式传递给函数,简言之,函数会 ...

  5. HttpClient_4 用法 由HttpClient_3 升级到 HttpClient_4 必看

    转自:http://www.blogjava.net/stevenjohn/archive/2012/09/26/388609.html HttpClient程序包是一个实现了 HTTP 协议的客户端 ...

  6. andriod学习之一

    今天安装了Android Studio, 但PinyinIME没有导入成功.然后看了Android的一些基础. 知道了Android的基本组件: Activity,服务,内容提供程序,广播接收器. 大 ...

  7. fiddler web开发调试工具的使用

    fiddler使用场景: (1)开发环境host配置: 通常情况下,配置host需要改变系统文件很不方便,在多个开发环境下切换很低效 fiddler提供了相对高效的host配置方法 (2)前后端接口调 ...

  8. linux IO调度

    I/O 调度算法再各个进程竞争磁盘I/O的时候担当了裁判的角色.他要求请求的次序和时机做最优化的处理,以求得尽可能最好的整体I/O性能.在linux下面列出4种调度算法CFQ (Completely ...

  9. 【python】类中@property使用

    在绑定属性时,如果我们直接把属性暴露出去,虽然写起来很简单,但是,没办法检查参数,导致可以把成绩随便改: s = Student() s.score = 9999 这显然不合逻辑.为了限制score的 ...

  10. change-resource-tags.sh

    #!/bin/bash ids=$(aws ec2 describe-instances --filter "Name=tag:Project,Values=ERPSystem" ...