private void button1_Click(object sender, EventArgs e) { var timeOld = DateTime.Now; var resultMsg = string.Empty; var criteria = new CriteriaTestuser(); criteria.UName = null; criteria.Count = Convert.ToInt32(textBox1.Text); OperateClass ope = new OperateClass(); ope.Assembly = "Library.Facade.SoaTest"; ope.Class = string.Format("{0}.{1}", ope.Assembly, "FacadeTestUser"); ope.Method = "QueryTestuserList"; ope.Parameters = new object[] { resultMsg, criteria }; ClientProxy proxy = new ClientProxy(); var resultOpc = proxy.Operate(ope); var list = (IList <ModelTestuser>)resultOpc.ResultObj; var timeNew = DateTime.Now; var timeSpan = timeNew - timeOld; var msg = string.Format("返回数据:{0} 条,耗时 {1} 秒!", list.Count, timeSpan.TotalSeconds); MessageBox.Show(msg); }
/// <summary> /// 类反射操作 /// </summary> public byte[] FacadeTestUserOperate(byte[] bytes) { byte[] returnObj = null; OperateClass ope = (OperateClass)SerializerDeserialize.Deserialize(bytes); if (ope == null) { return(returnObj); } if (string.IsNullOrWhiteSpace(ope.Method)) { return(returnObj); } IFacadeTestUser testUser = new Factories().InstanceTestUser(); Type myType = testUser.GetType(); MethodInfo myMethodInfo = myType.GetMethod(ope.Method, new Type[] { typeof(string).MakeByRefType(), typeof(object) }); ope.ResultObj = myMethodInfo.Invoke(testUser, ope.Parameters); returnObj = SerializerDeserialize.Serializer(ope); return(returnObj); }
public OperateClass FacadeTestUserOperate(OperateClass opc) { var clent = factory.CreateChannel(); var bytes = SerializerDeserialize.Serializer(opc); var resultBytes = clent.FacadeTestUserOperate(bytes); var resultOpe = (OperateClass)SerializerDeserialize.Deserialize(resultBytes); return(resultOpe); }
/// <summary> /// 统一反射操作 /// </summary> public byte[] Operate(byte[] bytes) { byte[] returnObj = null; OperateClass ope = (OperateClass)SerializerDeserialize.Deserialize(bytes); if (ope == null) { return(returnObj); } if (string.IsNullOrWhiteSpace(ope.Assembly)) { return(returnObj); } if (string.IsNullOrWhiteSpace(ope.Class)) { return(returnObj); } if (string.IsNullOrWhiteSpace(ope.Method)) { return(returnObj); } Assembly myAssembly = Assembly.Load(ope.Assembly); Type myType = myAssembly.GetType(ope.Class); var myTypeInstance = System.Activator.CreateInstance(myType); MethodInfo myMethodInfo = myType.GetMethod(ope.Method, new Type[] { typeof(string).MakeByRefType(), typeof(object) }); ope.ResultObj = myMethodInfo.Invoke(myTypeInstance, ope.Parameters); returnObj = SerializerDeserialize.Serializer(ope); return(returnObj); }