none
MSCRM 2011 Plugin 调用了自己写的WebService,WebService中有个执行sql server的存储过程,每次调用都是报超时的错误 RRS feed

  • 问题

  • WebSevice中定义的方法如下:

    /// <summary>
            /// 执行sql的存成过程
            /// </summary>
            /// <param name="ProcName">存储过程名称</param>
            /// <param name="param">参数</param>
            /// <returns></returns>
            [WebMethod]
            public string ExecProc(string ProcName, SqlParameter[] param)
            {
                LogService log = new LogService();
                log.WriteLog(LogType.DEBUG, "存储过程参数名:" + ProcName);
                try
                {
                    //int num = 0;
                    //DbHelperSQL.connectionString = PubConstant.GetConnectionString("SqlConnectionString");
                    //DbHelperSQL.RunProcedure(ProcNameAndParam, param, out num);
                    //return num.ToString();
                    using (SqlConnection con = new SqlConnection(PubConstant.GetConnectionString("SqlConnectionString")))
                    {
                        con.Open();
                        SqlCommand comm = new SqlCommand(ProcName, con);
                        log.WriteLog(LogType.DEBUG, "连接字符串:" + con.ConnectionString);
                        comm.CommandType = CommandType.StoredProcedure;
                        if (param != null)
                        {
                            comm.Parameters.Add(param);
                        }
                        comm.ExecuteNonQuery();
                    }
                    return "0";
                }
                catch (Exception ex)
                {
                    log.WriteLog(LogType.ERROR, "执行存储过程:" + ex.Message);
                    return ex.Message;
                }
            }

    下面是plugIn中我定义的一个类调用Web service中的方法执行sql存储过程的

     public static string Url = "http://localhost:5555/ISV/FundCrm/Service/WebService.asmx";
            public static string userName = "administrator";
            public static string passWord = "1231212";
            public static string domain = "crm";

    /// <summary>
            /// 执行存储过程
            /// </summary>
            /// <param name="ProcName,"></param>
            /// <param name="param"></param>
            public static string ExecProcBySql(string ProcName, WebSerice.SqlParameter[] param)
            {
                WebSerice.WebService wbs = new WebSerice.WebService();
                wbs.Credentials = new System.Net.NetworkCredential(userName, passWord, domain);
                wbs.Url = Url;
                string result = wbs.ExecProc(ProcName, param);
                return result;
            }

    下面是PlugIn中调用自定义类的代码

     /// <summary>
            /// 渠道拜访
            /// </summary>
            public void Execute(IServiceProvider serviceProvider)
            {
                // 获取执行上下文
                IPluginExecutionContext context = (IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext));

                // InputParameters属性包含所有输入参数数据
                if (context.InputParameters.Contains("Target") && context.InputParameters["Target"] is Entity)
                {
                    // 从输入参数中获取Target参数
                    Entity entity = (Entity)context.InputParameters["Target"];
                    //检测输入的Target参数,判断其逻辑名称是否是该实体.
                    if (entity.LogicalName == "crm_visit_record")
                    {
                        int num = 0;
                        string result = WebServiceHelp.ExecProcBySql("pz_cl_service_batch", null);
                        if (!Int32.TryParse(result, out num))
                        {
                            throw new Exception("PlugIn:执行存储过程pz_cl_service_batch出错:" + result);
                        }
                    }
                }
            }

    说明一下,我在PlugIn中调用WebService是添加的引用,然后在自定义类中把调用的地址改了,不知道跟这个有没有关系,新手求指教,求学习,求讲解。非常感觉。对了,执行的时候是能执行WebService中调用的那个方法的但是义执行到执行的那一行就会报超时,但是我在.net页面中也做过测试,是没有问题的,而且存储过程内容也不多,不应该会超时的

    2012年7月16日 7:19

全部回复

  • 1.把wbs的Timeout设置为600000,测试之

    2.把SqlCommand的CommandTimeout设置为600,测试之

    3.分别在自定义WebService项目和Plugin中记录日志,看一下是在什么地方报的错,再检查一下相应的代码

    4.在Plugin中设置try...catch(SoapException ex),看一下ex.Detail.InnerText里面是否存在更有价值的异常信息

    2012年7月30日 6:31