调用Ria Service中方法的各种方式
前端界面后台:
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中方法的各种方式的更多相关文章
- android 中activity调用远程service中的方法之 aidl的使用
		
服务端:只有服务,没有界面 1.编写interface文件,复制到 .aidl 文件中,并去掉其中的public 等修饰符.系统会自动在gen目录下生成对应的java文件 (对应本地调用中的接口文件 ...
 - android 中activity调用本地service中的方法。
		
1.自定义一个接口,暴露服务中的方法 public interface IService { /**服务中对外暴露的方法 */ void methodInService();} 2.自定一 ...
 - jQuery Ajax 方法调用 Asp.Net WebService 以及调用aspx.cs中方法的详细例子
		
一.jQuery Ajax 方法调用 Asp.Net WebService (引自Terry Feng) Html文件 <!DOCTYPE html PUBLIC "-//W3C//D ...
 - C#实现调用Java类中方法
		
基本思路: 用C#实现调用Java编写的类中的方法:重点是将Java编写的程序打包成Jar,然后使用开源工具IKVM将其转化成DLL控件,在.NET环境下调用. 分为以下步骤: 1.下载JDK6(注: ...
 - C#反射调用程序集类中方法
		
建立类 class OperatorClass { /// <summary> /// 加法 /// </summary> /// <param name="x ...
 - C#调用Dll文件中方法的简单应用
		
参考:http://www.cnblogs.com/Asuphy/p/4206623.html 直接看代码,最简单的引入,只需要3步: using System; using System.Colle ...
 - C#A类派生类强转基类IL居然还是可以调用派生类中方法的例子
		
大家都知道在C#中,如果B类继承自A类,如果一个对象是B类型的但是转换为A类型之后,这个对象是无法在调用属于B类型的方法的,如下例子: 基类A: public class A { } 派生类B: pu ...
 - 实现php Curl 调用不同项目中方法
		
之前为了实现跨项目调用方法,遇到的一些问题和解决方法总结. 话不多说,直接复制代码先跑了再说! jq代码. $.ajax({ type: "post", dataType: &qu ...
 - 通过反射对任意class类中方法赋值的方式
		
import org.apache.commons.lang3.StringUtils;import org.slf4j.Logger;import org.slf4j.LoggerFactory;i ...
 
随机推荐
- 下载ADT
			
用如下网址,将xx.x.x替换为想要的版本号,通过迅雷等新建下载输入如下网址,再通过离线安装,稳! http://dl.google.com/android/ADT-xx.x.x.zip 来自http ...
 - 05——C++自己合成的函数
			
C++编译器自己合成的构造函数: 默认构造函数 copy构造函数 copy assigment操作符 析构函数(编译器产生的析构时non-virtual) copy assignment(当含有con ...
 - HBase 实战(1)--HBase的数据导入方式
			
前言: 作为Hadoop生态系统中重要的一员, HBase作为分布式列式存储, 在线实时处理的特性, 备受瞩目, 将来能在很多应用场景, 取代传统关系型数据库的江湖地位. 本篇博文重点讲解HBase的 ...
 - jquery 中的几个函数方法
			
1.$.map(data,function(item,index){return XXX})处理每一个元素的函数.第一个参数是数组元素,第二个参数是该元素的索引值. 遍历data数组中的每个元素,并按 ...
 - [转载]QQ空间技术架构之深刻揭密
			
1. 拥有5.5亿的活跃用户 2. 过万台的设备 3. 数千万级别的同时在线 4. 数十亿级别的全站PV 5. P级的UGC存储量 6. 每天千亿级别的服务请求 图1--QQ空间海量服务数据规模 接下 ...
 - CVE-2014-6271 Bash漏洞利用工具
			
CVE-2014-6271 Bash漏洞利用工具 Exploit 1 (CVE-2014-6271) env x='() { :;}; echo vulnerable' bash -c "e ...
 - [Spring MVC] - Annotation验证
			
使用Spring MVC的Annotation验证可以直接对view model的简单数据验证,注意,这里是简单的,如果model的数据验证需要有一些比较复杂的业务逻辑性在里头,只是使用annotat ...
 - [转]C++ DLL远程注入与卸载函数
			
代码是别处的 第一个函数是成功的,第二个函数运行发现会将目标程序挂死,也许是目标程序有保护机制 支持Unicode编码. //------------------------------------- ...
 - SpringMVC学习系列(2) 之 经典的HelloWorld实现
			
前一篇简单介绍了Spring MVC的一些知识,下面就要开始学习如何把Spring MVC运用到具体的项目中去. 首先还是从一个简单的Hello World项目说起: 我机器的开发环境为: Ubunt ...
 - Qt StyleSheet样式表实例(转)
			
QT论坛看到的,收藏一下! 在涉及到Qt 美工的时候首先需要掌握CSS 级联样式表. 下面将通过几个例子来介绍一下怎样使用Qt中的部件类型设计.自定义的前台背景与后台背景的颜色: 如果需要一个文本编辑 ...