예제 #1
0
파일: WSRR.cs 프로젝트: huaminglee/Code
    private string ExecuteRestful(DataSet pdsWSID, DataSet pdsRequest)
    {
        string strParam = "";
        string strType = pdsWSID.Tables[0].Rows[0]["WSMethod"].ToString().ToLower();
        string strUnicode = pdsWSID.Tables[0].Rows[0]["WSUnicode"].ToString().ToUpper();

        for (int j = 0; j < pdsWSID.Tables[0].Rows.Count; j++)
        {
            if (pdsWSID.Tables[0].Rows[j]["ParamName"] == DBNull.Value)
            {
                continue;
            }
            string strParamName = pdsWSID.Tables[0].Rows[j]["ParamName"].ToString();
            DataRow[] drList = pdsRequest.Tables[0].Select("ParamName='" + strParamName + "'");

            if (drList.Length > 0)
            {
                if (strType == "get")
                {
                    strParam += drList[0]["ParamName"].ToString() + "=";
                    strParam += drList[0]["ParamValue"].ToString() + "&";

                    //Microsoft.JScript.GlobalObject.escape(
                }
                else if (strType == "post")
                {
                    strParam = drList[0]["ParamValue"].ToString();
                }
            }
            else
            {

                if (pdsWSID.Tables[0].Rows[j]["DefaultValue"] != DBNull.Value)
                {
                    if (strType == "get")
                    {
                        strParam += strParamName + "=";
                        strParam += pdsWSID.Tables[0].Rows[j]["DefaultValue"].ToString() + "&";
                    }
                    else if (strType == "post")
                    {
                        strParam = drList[0]["ParamValue"].ToString();
                    }
                }
                else
                {
                    if (pdsWSID.Tables[0].Rows[j]["ParamMustFlag"].ToString() == "1")
                    {
                        throw new Exception(strParamName + "参数没有被赋值!");
                    }
                }
            }

        }


        string strResult = "";
        HttpTools http = new HttpTools();
        string strurl = GetURL(pdsWSID);

        if (strType == "get")
        {
            strResult = http.CreateHttpGet(strurl + strParam, false, strUnicode);

        }
        else if (strType == "post")
        {
            strResult = http.CreateHttpPost(strurl, strParam, false, strUnicode);
        }

        return strResult;

    }