吹风

导航

 

服务:

        [WebMethod]
        public string HelloWorld()
        {
            return "您好!";
        }

silverlight中代码:

namespace DynamicDemo
{
    public partial class MainPage : UserControl
    {
        public MainPage()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, RoutedEventArgs e)
        {
            CallService("DynamicDemo.Server.RefServiceSoapClient", "HelloWorld", new object[] { }, new EventHandler<DynamicDemo.Server.HelloWorldCompletedEventArgs>(aa_HelloWorldCompleted));
        }

        void aa_HelloWorldCompleted(object sender, Server.HelloWorldCompletedEventArgs e)
        {
            MessageBox.Show("吹风说:" + e.Result);
        }

        public void CallService(string classstring, string methodstring,object[] paramstring,Delegate completedel)
        {
            Type tp = Type.GetType(classstring);

            EventInfo Event = tp.GetEvent(methodstring+"Completed");

            MethodInfo method = tp.GetMethod(methodstring+"Async", new Type[] { }, new ParameterModifier[] { });

            var chuifeng = tp.Assembly.CreateInstance(classstring);

            Event.AddEventHandler(chuifeng, completedel);

            method.Invoke(chuifeng, paramstring);

        }
    }
}

posted on 2010-10-28 09:18  吹风  阅读(950)  评论(0编辑  收藏  举报