调用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(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);
        }
    }
}

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>

时间: 2024-08-30 17:43:55

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

JAVA 调用Web Service的方法(转载)

JAVA 调用Web Service的方法 1.使用HttpClient 用到的jar文件:commons-httpclient-3.1.jar 方法: 预先定义好Soap请求数据,可以借助于XMLSpy Professional软件来做这一步生成. String soapRequestData = "<?xml version=\"1.0\" encoding=\"utf-8\"?>" +     "<soap12:

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

建立类 class OperatorClass { /// <summary> /// 加法 /// </summary> /// <param name="x"></param> /// <param name="y"></param> /// <returns></returns> /// public static int Add(int x, int y) { r

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

服务端:只有服务,没有界面 1.编写interface文件,复制到 .aidl 文件中,并去掉其中的public 等修饰符.系统会自动在gen目录下生成对应的java文件  (对应本地调用中的接口文件) 2.编写service,其中内部类的自定义bind 只需要继承Stub即可.(本地调用则需要继承Bind 并实现 interface接口) 1 public class PayService extends Service { 2 3 @Override 4 public IBinder onB

C#实现调用Java类中方法

基本思路: 用C#实现调用Java编写的类中的方法:重点是将Java编写的程序打包成Jar,然后使用开源工具IKVM将其转化成DLL控件,在.NET环境下调用. 分为以下步骤: 1.下载JDK6(注:JDK7下可能不支持,建议使用JDK6和Eclipse),进行安装,然后配置环境变量Path,将JDK安装的路径(例如:D:\Program Files\Java\jdk1.6.0_10\bin)添加到Path变量后面,如图所示: 用cmd打开DOS框,输入javac就可以查看是否配置成功,配置成功

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

import org.apache.commons.lang3.StringUtils;import org.slf4j.Logger;import org.slf4j.LoggerFactory;import org.springframework.stereotype.Component; import java.lang.reflect.Method; @Componentpublic class SetPlatformUtils { private static final CoreSe

ORACLE存储过程调用Web Service

1. 概述 最近在ESB项目中,客户在各个系统之间的服务调用大多都是在oracle存储过程中进行的,本文就oracle存储过程调用web service来进行说明.其他主流数据库,比如mysql和sql service,调用web service的方法这里就不做介绍了,本文主要用来介绍oracle存储过程调用Web Service的方法. 众所周知,在Web Service通过HTTP协议发送请求和接收结果时,发送的请求内容和结果内容都采用XML格式封装,并增加了一些特定的HTTP消息头,以说明

项目中Ajax调用ashx页面中的Function的实战

前台页面: 使用几个display=none的空间存储DropdownList中的值,点击Search Button后刷新页面再次给DropdownList赋值使用 <%@ Page Language="c#" CodeBehind="MallListCAM.aspx.cs" AutoEventWireup="True" Inherits="PRCSales_internal.Mall.MallListCAM" Enab

在Java filter中调用service层方法

在项目中遇到一个问题,在 Filter中注入 Serivce失败,注入的service始终为null.如下所示: 1 public class WeiXinFilter implements Filter{ 2 3 @Autowired 4 private UsersService usersService; 5 6 public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)

ASP.NET4.0中JavaScript脚本调用Web Service 方法

环境:VS2019  .net 4.0 framework 根据教材使用ScriptManager在JavaScript中调用Web service 时,失败.现将过程和解决方法记录如下: 1.定义Web Service using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.Services; namespace AjaxTest1 { /// <