zoukankan      html  css  js  c++  java
  • silverlight 反射调用WebService

    服务:

    1 [WebMethod]
    2 public string HelloWorld()
    3 {
    4     return "您好!";
    5 }

    silverlight中代码:

    01 namespace DynamicDemo
    02 {
    03     public partial class MainPage : UserControl
    04     {
    05         public MainPage()
    06         {
    07             InitializeComponent();
    08         }
    09  
    10         private void button1_Click(object sender, RoutedEventArgs e)
    11         {
    12             CallService("DynamicDemo.Server.RefServiceSoapClient""HelloWorld"new object[] { },new EventHandler<DynamicDemo.Server.HelloWorldCompletedEventArgs>(aa_HelloWorldCompleted));
    13         }
    14  
    15         void aa_HelloWorldCompleted(object sender, Server.HelloWorldCompletedEventArgs e)
    16         {
    17             MessageBox.Show("吹风说:" + e.Result);
    18         }
    19  
    20         public void CallService(string classstring, string methodstring,object[] paramstring,Delegate completedel)
    21         {
    22             Type tp = Type.GetType(classstring);
    23  
    24             EventInfo Event = tp.GetEvent(methodstring+"Completed");
    25  
    26             MethodInfo method = tp.GetMethod(methodstring+"Async"new Type[] { }, newParameterModifier[] { });
    27  
    28             var chuifeng = tp.Assembly.CreateInstance(classstring);
    29  
    30             Event.AddEventHandler(chuifeng, completedel);
    31  
    32             method.Invoke(chuifeng, paramstring);
    33  
    34         }
    35     }
    36 }
    Powered By D&J (URL:http://www.cnblogs.com/Areas/)
  • 相关阅读:
    模拟城市:我是市长
    IOTA私有链简单搭建
    SOUL软件小结
    ubuntu 16.04 安装node.js 8.x
    Ubuntu下Hyperledger Fabric v0.6安装部署
    区块链关键术语与概念
    Windows Server 2019安装OpenSSH Server简明教程
    Windows10和Windows Server 2019支持OpenSSH
    TypeError: __init__() got an unexpected keyword argument 'serialized_options'
    无法从路径’NuGet.CommandLine.2.7.1.nupkg’读取包
  • 原文地址:https://www.cnblogs.com/Areas/p/2169468.html
Copyright © 2011-2022 走看看