调用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 ...
随机推荐
- __attribute__ 你知多少?
GNU C 的一大特色就是__attribute__ 机制.__attribute__ 可以设置函数属性(Function Attribute ).变量属性(Variable Attribute )和 ...
- 图片加载完后执行js
<script> window.onload=function(){ var liwidth = $('.imgul ...
- id 和 instancetype
静态数据类型 默认情况下所有的数据类型都是静态数据类型 静态数据类型的特点: 1 在编译时就知道变量的类型 2 知道变量中有哪些属性和方法 3 在编译的时候就可以访问这些属性和方法 4 并且如果是通过 ...
- Qt 手动添加ui文件到工程(转)
制作ui文件 先应该用Qt Designer绘制一个自己的界面,并存为myform.ui(这里的myform可以用自己喜欢的名字代替).在制作自己的界面文件时要注意以下几个要点: 1.要记住ui文件的 ...
- 每日学习心得:$.extend()方法和(function($){...})(jQuery)详解
2014-02-09 前言: 节后头两天上班,主要是调整工作状态.项目也不是很紧,趁着周末把年前遇到了一些关于JS和JQuery的一些问题给总结一下.主要是介绍JQuery的extend方法和(fun ...
- 调Windows 7的图片浏览器查看图片
public static void viewPicFromWindows(string pPicPath) { if (pPicPath!="" && Syste ...
- eclipse美化
// */ // ]]> eclipse美化 Table of Contents 1 中文字体 2 皮肤 3 emacs+ 1 中文字体 win7下打开eclipse3.7中文字体很小,简直 ...
- phpnow修改默认站点根目录的方法
本文转载自:http://blog.csdn.net/andy_eeipla/article/details/7832082 对于phpnow,经测试,修改Apache-20\conf\extra\h ...
- PHP 开发的 API 多版本管理实践
遇到的情况 本文针对移动互联网客户端需要兼容旧版的情况,强制升级到最新版本的 app 不在讨论之列. 在 bugtags.com 项目中,我们的版本遵循下面规范.1.0.1大功能.小更新.bug 修正 ...
- 再看静态static及相关知识汇集
在C#程序中,没有全局变量的概念,这意味着所有的成员变量只有该类的实例才能操作这些数据,这起到了“信息隐藏”的作用.但有些时候,这样做却不是个明智的选择.C#中静态变量——它在类中类似全局变量,保存类 ...