WebAPI接口调用

合集下载
相关主题
  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

API传输文件的接口调用方式:
using (WebClient client = new WebClient())
{
string sWFDocumentNo = lblWFDocumentNo.Text;
string ssWFApplyby = lblWFApplyBy.Text;
if (ssWFApplyby.Trim() == "")
ssWFApplyby = lblWFApplyBy.Text;
if (ssWFApplyby.Length > 5 && ssWFApplyby.ToLower().Substring(0, 4) == "gwkf")
{
ssWFApplyby = ssWFApplyby.Substring(5, ssWFApplyby.Length - 5);
}
string sValue = System.Text.Encoding.Default.GetString(fileFirstUpload.FileBytes);
string[] str = new string[] { };

string url = "";
RUC_Config rUC_Config = new RucDA().GetRUC_ConfigByWebRefName("PLAFToSAPCheck");
if (rUC_Config != null)
{
if (rUC_Config.ServerURL != null && rUC_Config.ServerURL != "")
{
url = rUC_Config.ServerURL;
}
}
var parameters = new NameValueCollection();
parameters.Add("sWFApplyby", ssWFApplyby);
parameters.Add("sWFDocumentNo", sWFDocumentNo);
parameters.Add("IfCheck", "C");
parameters.Add("Filename", fileFirstUpload.FileName);
parameters.Add("sValue", sValue);

(WFFlowID.ToString(), ItemID, System.Reflection.MethodBase.GetCurrentMethod().DeclaringType, url + "-SAP 验证开始 WFApplyby[" + ssWFApplyby + "]WFDocumentNo[" + sWFDocumentNo + "]");
var response = Encoding.UTF8.GetString(client.UploadValues(url, "Post", parameters));

if (response != "\"\"")
{
ErroMes += response;
Log4NetHelper.Fatal(WFFlowID.ToString(), ItemID, MethodBase.GetCurrentMethod().DeclaringType, "接口返回信息:" + response.ToString());
}
(WFFlowID.ToString(), ItemID, System.Reflection.MethodBase.GetCurrentMethod().DeclaringType, url + "-SAP 验证结束 WFApplyby[" + ssWFApplyby + "]WFDocumentNo[" + sWFDocumentNo + "]");
}


API接口的写法:

public string PLAFToSAPCheck(FormDataCollection form)
{
string sErr = "";
string sWFApplyby = form.Get("sWFApplyby");
string sWFDocumentNo = form.Get("sWFDocumentNo");
string IfCheck = form.Get("IfCheck");
string Filename = form.Get("Filename");
string sValue = form.Get("sValue");

try
{
sWFApplyby = sWFApplyby.Trim(';').ToUpper();
byte[] byteArray = System.Text.Encoding.Default.GetByte

s(sValue);
DataTable dt = dtByOpenCSV(byteArray, out sErr);
if (sErr != "")
{
ErrMessage += "data生成报错:" + sErr + "
";
LogMessage = string.Format("锁加单验证报表数据报错 WFApplyby[{0}]WFDocumentNo[{1}]错误信息[{2}]", sWFApplyby, sWFDocumentNo, ErrMessage);
(MethodBase.GetCurrentMethod().DeclaringType, LogMessage);
}
else
{
PLAF_SAPMoneyForm.ZMMFG0001_CREAT_INFOREORD_01 zHRGWBD = new PLAF_SAPMoneyForm.ZMMFG0001_CREAT_INFOREORD_01();

DataTable dt_RUC_Config = new WorkFlowDA().GetRUC_Config("SAPMoneyForm");
if (dt_RUC_Config != null && dt_RUC_Config.Rows.Count > 0)
zHRGWBD.Url = dt_RUC_Config.Rows[0]["ServerURL"].ToString();
zHRGWBD.Credentials = new workCredential("oauser", "oauser");

zHRGWBD.Timeout = 600000;

int m = dt.Rows.Count;
PLAF_SAPMoneyForm.Zmms0003[] zm3 = new PLAF_SAPMoneyForm.Zmms0003[m];
PLAF_SAPMoneyForm.Zmms0004[] zm4 = new PLAF_SAPMoneyForm.Zmms0004[m];
PLAF_SAPMoneyForm.Zmms0005[] zm5 = new PLAF_SAPMoneyForm.Zmms0005[m];
zm3 = TableTostrArray_One(sWFDocumentNo, dt);
DataSet ds = new DataSet();
ds.Tables.Add(dt);
System.IO.StringWriter sw = new System.IO.StringWriter();
System.Xml.XmlTextWriter xw = new System.Xml.XmlTextWriter(sw);
ds.WriteXml(xw);
string sss = sw.ToString();
LogMessage = string.Format("锁加单验证报表数据 WFApplyby[{0}]WFDocumentNo[{1}]错误信息[{2}]", sWFApplyby, sWFDocumentNo, sss);
(MethodBase.GetCurrentMethod().DeclaringType, LogMessage);
zm4 = TableTostrArray_Two(IfCheck, CreateZMMS004());
PLAF_SAPMoneyForm.Zmms0008 zm8 = new PLAF_SAPMoneyForm.Zmms0008();
zm8.Filename = Filename;
zm8.Zdomain = sWFApplyby;
zm8.Zformno = sWFDocumentNo;
LogMessage = string.Format("锁加单验证开始 WFApplyby[{0}]WFDocumentNo[{1}]", sWFApplyby, sWFDocumentNo );
(MethodBase.GetCurrentMethod().DeclaringType, LogMessage);

zHRGWBD.Zmmfg0001CreatInforeord01(zm8, ref zm3, ref zm5, ref zm4);
var returnZm5 = ConvertZm5(zm5);/////错误的明细,如果没有错误就是为空
var ShowData = BuiltTable(zm4);////错误信息
if (returnZm5 != null && returnZm5.Rows.Count > 0)
{
stri

ng XmlStr = DataTableToString(returnZm5);
var msg = RemoveHTMLTags(XmlStr);
sErr += msg.ToString();
}
foreach (PLAF_SAPMoneyForm.Zmms0003 s in zm3)
{
if (s.Message != null && s.Message.Trim() != "")
{
string E = "";
if (s.Znum2 != null && s.Znum2.Trim() != "")
E = "序号为:" + s.Znum2 + "报错,报错信息为:";
sErr += E + s.Message + ";";
}
}
if (!string.IsNullOrWhiteSpace(sErr))
{
ErrMessage += sErr;
LogMessage = string.Format("锁加单验证异常 WFApplyby[{0}]WFDocumentNo[{1}]错误信息[{2}]", sWFApplyby, sWFDocumentNo, ErrMessage);
LogHelper.ERROR(MethodBase.GetCurrentMethod().DeclaringType, LogMessage);
}
else
{
LogMessage = string.Format("锁加单验证完成 WFApplyby[{0}]WFDocumentNo[{1}]", sWFApplyby, sWFDocumentNo);
(MethodBase.GetCurrentMethod().DeclaringType, LogMessage);
}
}
}
catch (Exception ex)
{
sErr += ex.Message.ToString() + "
" + ex.StackTrace;
ErrMessage += sErr + "
";
LogMessage = string.Format("锁加单验证失败 WFApplyby[{0}]WFDocumentNo[{1}]", sWFApplyby, sWFDocumentNo);
LogHelper.ERROR(MethodBase.GetCurrentMethod().DeclaringType, ex, LogMessage);
}
return ErrMessage;
}


相关文档
最新文档