Ejemplo n.º 1
0
        /// <summary>
        /// 动态调用类方法,传类实例、类方法信息
        /// </summary>
        /// <param name="obj"></param>
        /// <param name="mi"></param>
        /// <param name="htParam"></param>
        /// <returns></returns>
        public static object InvokeMethod(object obj, MethodInfo mi, Hashtable htParam)
        {
            try
            {
                //参数
                ParameterInfo[] paramList = mi.GetParameters();
                object[]        objParams = new object[paramList.Length];
                for (int i = 0; i < paramList.Length; i++)
                {
                    string paramValue = "";
                    foreach (DictionaryEntry de in htParam)
                    {
                        if (de.Key.ToString().Equals(paramList[i].Name, StringComparison.CurrentCultureIgnoreCase))
                        {
                            paramValue = de.Value.ToString();
                            break;
                        }
                    }
                    objParams[i] = CreateParamObj(paramValue, paramList[i].ParameterType);
                }

                return(mi.Invoke(obj, objParams));
            }
            catch (Exception e)
            {
                MyLog.WriteExceptionLog("WebServiceHelper.InvokeMethod", e,
                                        string.Format("\r\n\tmethod:{0}", mi == null ? "method为空" : mi.Name));
                return(null);
            }
        }
Ejemplo n.º 2
0
 /// <summary>
 /// 动态调用类方法,传类名、类方法
 /// </summary>
 /// <param name="t"></param>
 /// <param name="methodname"></param>
 /// <param name="htParam"></param>
 /// <returns></returns>
 public static object InvokeMethod(Type t, string methodname, Hashtable htParam)
 {
     try
     {
         object     obj = Activator.CreateInstance(t);
         MethodInfo mi  = t.GetMethod(methodname);
         return(InvokeMethod(obj, mi, htParam));
     }
     catch (Exception e)
     {
         MyLog.WriteExceptionLog("WebServiceHelper.InvokeMethod", e,
                                 string.Format("\r\n\tmethod:{0}", methodname));
         return(null);
     }
 }
Ejemplo n.º 3
0
        /// <summary>
        /// 进行DES解密。
        /// </summary>
        /// <param name="pToDecrypt">要解密的以Base64</param>
        /// <param name="sKey">密钥,且必须为8位,不足8位系统自动补齐。</param>
        /// <returns>已解密的字符串。</returns>
        public static string Decrypt(string pToDecrypt, string _Key)
        {
            string sKey = (_Key + ConBaseString).Substring(0, 8);

            try
            {
                byte[] inputByteArray = Convert.FromBase64String(pToDecrypt);
                using (DESCryptoServiceProvider des = new DESCryptoServiceProvider())
                {
                    des.Key = ASCIIEncoding.ASCII.GetBytes(sKey);
                    des.IV  = ASCIIEncoding.ASCII.GetBytes(sKey);
                    System.IO.MemoryStream ms = new System.IO.MemoryStream();
                    string str = "";
                    try
                    {
                        using (CryptoStream cs = new CryptoStream(ms, des.CreateDecryptor(), CryptoStreamMode.Write))
                        {
                            cs.Write(inputByteArray, 0, inputByteArray.Length);

                            cs.FlushFinalBlock();
                            cs.Close();
                            str = Encoding.UTF8.GetString(ms.ToArray());
                        }
                    }
                    catch
                    {
                        str = pToDecrypt;
                    }
                    ms.Close();
                    return(str);
                }
            }
            catch (Exception e)
            {
                MyLog.WriteExceptionLog("MySecurity.Decrypt", e, pToDecrypt);
                return("");
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// 通过webservice接口,自动创建代码类
        /// </summary>
        /// <param name="url"></param>
        /// <param name="classname"></param>
        /// <param name="methodname"></param>
        /// <returns></returns>
        public static Type GetWebServiceType(string url, string classname)
        {
            #region 实现过程

            if ((classname == null) || (classname == ""))
            {
                classname = WebServiceHelper.GetWsClassName(url);
            }

            try
            {
                //获取WSDL ,得到sdi
                WebClient                  wc     = new WebClient();
                Stream                     stream = wc.OpenRead(url + "?WSDL");
                ServiceDescription         sd     = ServiceDescription.Read(stream);
                ServiceDescriptionImporter sdi    = new ServiceDescriptionImporter();
                sdi.AddServiceDescription(sd, "", "");

                //得到ccu
                string          @namespace = "EnterpriseServerBase.WebService.DynamicWebCalling";
                CodeNamespace   cn         = new CodeNamespace(@namespace);
                CodeCompileUnit ccu        = new CodeCompileUnit();
                ccu.Namespaces.Add(cn);
                sdi.Import(cn, ccu);

                //设定编译参数
                CompilerParameters cplist = new CompilerParameters();
                cplist.GenerateExecutable = false;
                cplist.GenerateInMemory   = true;
                cplist.ReferencedAssemblies.Add("System.dll");
                cplist.ReferencedAssemblies.Add("System.XML.dll");
                cplist.ReferencedAssemblies.Add("System.Web.Services.dll");
                cplist.ReferencedAssemblies.Add("System.Data.dll");

                //编译
                CSharpCodeProvider icc = new CSharpCodeProvider();
                CompilerResults    cr  = icc.CompileAssemblyFromDom(cplist, ccu);

                //出错信息
                if (true == cr.Errors.HasErrors)
                {
                    System.Text.StringBuilder sb = new System.Text.StringBuilder();
                    foreach (System.CodeDom.Compiler.CompilerError ce in cr.Errors)
                    {
                        sb.Append(ce.ToString());
                        sb.Append(System.Environment.NewLine);
                    }
                    throw new Exception(sb.ToString());
                }

                //自动创建类信息
                Assembly assembly = cr.CompiledAssembly;
                Type     t        = assembly.GetType(@namespace + "." + classname, true, true);

                return(t);
            }
            catch (Exception e)
            {
                MyLog.WriteExceptionLog("WebServiceHelper.GetWebServiceType", e,
                                        string.Format("\r\n\turl:{0}", url));
                return(null);
            }

            #endregion
        }