silverlight 反射调用WebService
时间:2010-10-28 来源:吹风
[WebMethod] public string HelloWorld() { return "您好!"; }
silverlight中代码:
namespace DynamicDemo { public partial class MainPage : UserControl { public MainPage() { InitializeComponent(); } private void button1_Click(object sender, RoutedEventArgs e) { Type tp = Type.GetType("DynamicDemo.Server.RefServiceSoapClient"); EventInfo Event = tp.GetEvent("HelloWorldCompleted"); MethodInfo method = tp.GetMethod("HelloWorldAsync", new Type[] { }, new ParameterModifier[] { }); var chuifeng = tp.Assembly.CreateInstance("DynamicDemo.Server.RefServiceSoapClient"); Event.AddEventHandler(chuifeng, new EventHandler<DynamicDemo.Server.HelloWorldCompletedEventArgs>(aa_HelloWorldCompleted)); method.Invoke(chuifeng, new object[] { }); } void aa_HelloWorldCompleted(object sender, Server.HelloWorldCompletedEventArgs e) { MessageBox.Show("吹风说:" + e.Result); } } }
相关阅读 更多 +