コード例 #1
0
 /// <summary>
 /// 设置凭证与超时时间
 /// </summary>
 /// <param name="request"></param>
 private void SetWebRequest(HttpWebRequest request)
 {
     request.Credentials = CredentialCache.DefaultCredentials;
     request.Timeout     = 60000;
     if (is_proxy != "0")
     {
         LogHelp.WriteInfoLog("JLF.Form.WebService", "代理服务器设置!");
         ProxySetting(request, "http://" + proxy_host + ":" + proxy_port, proxy_user_name, proxy_password);
     }
     else
     {
         LogHelp.WriteInfoLog("JLF.Form.WebService", "代理服务器不设置!");
     }
 }
コード例 #2
0
        /// <summary>
        /// 执行查询方法
        /// </summary>
        /// <param name="_Url">Webservice Url 传null,系统默认url</param>
        /// <param name="MethodType">方法类型 POST GET SOAP</param>
        /// <param name="MethodName">方法名</param>
        /// <param name="Parms">参数集合</param>
        /// <param name="Msg">消息</param>
        /// <returns></returns>
        public ReturnMessage Execute_Get_Method(string _Url, string MethodType, string MethodName, Hashtable Parms, out string Msg)
        {
            Msg = string.Empty;
            ReturnMessage RMsg = new ReturnMessage();
            XmlDocument   xd   = new XmlDocument();

            if (!string.IsNullOrEmpty(_Url))
            {
                m_url = _Url;
            }
            try
            {
                LogHelp.WriteInfoLog("JLFFormWebService", "Execute_Get_Method:" + MethodName + "(执行Payroll接口)");
                switch (MethodType)
                {
                case WebMethodType.GET: xd = this.Execute_GetWebService(MethodName, Parms, out Msg); break;

                case WebMethodType.POST: xd = this.Execute_PostWebService(MethodName, Parms, out Msg); break;

                default: xd = this.Execute_SoapWebService(MethodName, Parms, null, out Msg); break;
                }

                try
                {
                    LogHelp.WriteInfoLog("JLFFormWebService", "Execute_Get_Method:" + MethodName + "(调用成功,解析返回结果)");
                    string strReturnValue = xd.InnerText;
                    RMsg.Status  = true;
                    RMsg.Message = "获取数据成功!";
                    RMsg.Entity  = strReturnValue;
                    LogHelp.WriteInfoLog("JLFFormWebService", "Execute_Get_Method:" + MethodName + "(解析返回结果成功)");
                }
                catch (Exception ex)
                {
                    Msg = @"返回值格式不正确,请检查!正确格式:
                           <FlowER><Item><TextField>Text A</TextField><ValueField>Value A</ValueField></Item>...</FlowER>";
                    LogHelp.WriteInfoLog("JLFFormWebService", "Execute_Get_Method:" + MethodName + "(解析返回结果失败:" + Msg + ")");
                    throw new Exception(Msg);
                }
            }
            catch (Exception ex)
            {
                RMsg.Status  = false;
                RMsg.Message = ex.Message;
                Msg          = ex.Message;
                LogHelp.WriteInfoLog("JLFFormWebService", "Execute_Get_Method:" + MethodName + "(调用异常:" + Msg + ")");
            }

            return(RMsg);
        }
コード例 #3
0
        /// <summary>
        /// 代理服务器设置
        /// </summary>
        /// <param name="request"></param>
        /// <param name="ProxyAddress">代理服务地址</param>
        /// <param name="ProxyUser">用户</param>
        /// <param name="ProxyKey">密码</param>
        public void ProxySetting(WebRequest request, string ProxyAddress, string ProxyUser, string ProxyKey)
        {
            try
            {
                WebProxy proxy = new WebProxy(ProxyAddress, true);

                if (!string.IsNullOrEmpty(ProxyAddress) && !string.IsNullOrEmpty(ProxyUser) && !string.IsNullOrEmpty(ProxyKey)) //如果地址为空,则不需要代理服务器
                {
                    proxy.Credentials = new NetworkCredential(ProxyUser, ProxyKey);                                             //从配置封装参数中创建
                }
                request.Proxy = proxy;                                                                                          //赋予 request.Proxy
                LogHelp.WriteInfoLog("JLF.Form.WebService", "代理服务器设置成功!代理服务host和port:" + ProxyAddress + "用户名:" + ProxyUser);
            }
            catch (Exception ex)
            {
                LogHelp.WriteErrorLog("JLF.Form.WebService", "代理服务器设置失败!代理服务host和port:" + ProxyAddress + "用户名:" + ProxyUser + ",错误原因:" + ex.Message);
            }
        }
コード例 #4
0
        /// <summary>
        /// 执行Check方法
        /// </summary>
        /// <param name="_Url">Webservice Url 传null,系统默认url</param>
        /// <param name="MethodType">方法类型 POST GET SOAP</param>
        /// <param name="MethodName">方法名</param>
        /// <param name="Parms">参数集合</param>
        /// <param name="Msg">消息</param>
        /// <returns></returns>
        public ReturnMessage Execute_Check_Method(string _Url, string MethodType, string MethodName, Hashtable Parms, out string Msg)
        {
            Msg = string.Empty;
            ReturnMessage RMsg = new ReturnMessage();
            XmlDocument   xd   = new XmlDocument();

            if (!string.IsNullOrEmpty(_Url))
            {
                m_url = _Url;
            }
            try
            {
                LogHelp.WriteInfoLog("JLFFormWebService", "Execute_Check_Method:" + MethodName + "(执行Payroll接口)");
                switch (MethodType)
                {
                case WebMethodType.GET: xd = this.Execute_GetWebService(MethodName, Parms, out Msg); break;

                case WebMethodType.POST: xd = this.Execute_PostWebService(MethodName, Parms, out Msg); break;

                default: xd = this.Execute_SoapWebService(MethodName, Parms, null, out Msg); break;
                }

                string strReturnValue = xd.InnerText;

                try
                {
                    LogHelp.WriteInfoLog("JLFFormWebService", "Execute_Check_Method:" + MethodName + "(调用成功,解析返回结果)");
                    XmlDocument xdoc = new XmlDocument();
                    xdoc.LoadXml(strReturnValue);
                    XmlNode objHeadNode = xdoc.SelectSingleNode("//Head");
                    RMsg.form_no = objHeadNode.SelectSingleNode("form_no").InnerText.Trim();
                    RMsg.Status  = Convert.ToBoolean(objHeadNode.SelectSingleNode("Status").InnerText.Trim());
                    RMsg.Message = objHeadNode.SelectSingleNode("Message").InnerText.Trim();
                    LogHelp.WriteInfoLog("JLFFormWebService", "Execute_Check_Method:" + MethodName + "(解析返回结果成功)");
                }
                catch (Exception ex)
                {
                    Msg = @"返回值格式不正确,请检查!正确格式:
                                                        <FlowER>
                                                          <Head>       
                                                              <form_no>表单号</form_no>
                                                              <Status>状态</Status>
                                                              <Message>消息</Message>
                                                          </Head>    
                                                          <Body> 
                                                          </Body>    
                                                       </FlowER>";
                    LogHelp.WriteInfoLog("JLFFormWebService", "Execute_Check_Method:" + MethodName + "(解析返回结果失败:" + Msg + ")");
                    throw new Exception(Msg);
                }
            }
            catch (Exception ex)
            {
                RMsg.Status  = false;
                RMsg.Message = ex.Message;
                Msg          = ex.Message;
                LogHelp.WriteInfoLog("JLFFormWebService", "Execute_Check_Method:" + MethodName + "(调用异常:" + Msg + ")");
            }

            return(RMsg);
        }