【问题标题】:Dynamics NAV Webservice Fails on 2nd LoopDynamics NAV Web 服务在第二个循环中失败
【发布时间】:2014-12-11 16:34:45
【问题描述】:

我创建了一个 C# 程序来读取管道 ("|") 分隔的文件并创建采购发票和行。本质上,我让它遍历每一行,如果没有使用“报告ID”,它会创建一个标题,然后是行,如果已经创建了标题,它会跳过标题创建并应该添加后续行.但是,当我到达该行的对象分配时,它会出错:

“ArgumentException 未处理” “必须指定解析字符串的有效信息。”

PIheader 函数工作正常,所以我没有在这里包含。如果需要更多信息/代码,请告知。

//Parse selected SAE File
SAEline[] sae = ParseSAE.Parse(file);

//Begin Analyzing Data
int saesize = sae.Length;
int i = 0;
List<string> cashIDs = new List<string>();
string paymentterms = "";
string invno = "";
string company = "";
string[] getcompany = new string[2];
string reportid = sae[i].ReportID;
int lineno = 0;
while(i < 10) //limit the loop for testing
//while (i < saesize)
{
    if (sae[i].ReportEntryPaymentCodeCode != "CBCP")
    {
        if (!cashIDs.Contains(reportid))
        {
            cashIDs.Add(reportid);
            getcompany = WebServices.GetCompany(sae[i].EmployeeID.ToUpper());
            paymentterms = sae[i].ReportEntryPaymentCodeCode;
            invno = WebServices.PIheader(getcompany[0], getcompany[1], 0, sae[i]);
            lineno = 0;
        }
        lineno = lineno + 10000;
        company = getcompany[0];
        lineno = WebServices.PIlines(invno, lineno, company, sae[i]);
    }
    i++;
}

WebService.cs 包含:

//Web Service Client
        PurchLines.PurchLines_PortClient piClient =
            new PurchLines_PortClient((System.ServiceModel.Channels.Binding)basicHttpBindingNTLM,
                new EndpointAddress("URL" + company + "/Page/PurchLines"));

        //Conditional variables
        string joblinetype = "";
        string qty = "";


        if  (sae.ReportEntryCustom1 == "Billable")
        {
            joblinetype = "3";
        }

        if (sae.BusinessDistance == "")
        {
            if (sae.ReportCustom2 == "")
            {
                qty = "1";
            }
            else
            {
                qty = sae.ReportCustom2;
            }
        }
        else
        {
            qty = sae.BusinessDistance;
        }

        string unitcost = (Convert.ToDecimal(sae.ReportEntryApprovedAmount)/Convert.ToDecimal(qty)).ToString();

        //Line Creation
        PurchLines.PurchLines line = new PurchLines.PurchLines()
        {
            No = sae.JournalAccountCode,
            Line_No = Convert.ToInt16(lineno),
            Line_NoSpecified = true,
            Job_Line_TypeSpecified = true,
            Job_Line_Type = (PurchLines.Job_Line_Type) (Enum.Parse(typeof (PurchLines.Job_Line_Type), joblinetype)),
            QuantitySpecified = true,
            Quantity = Convert.ToDecimal(qty),
            TypeSpecified = true,
            Type = (PurchLines.Type) (Enum.Parse(typeof (PurchLines.Type), "1")),
            Direct_Unit_CostSpecified = true,
            Direct_Unit_Cost = Convert.ToDecimal(unitcost),
            Job_Unit_PriceSpecified = true,
            Job_Unit_Price = Convert.ToDecimal(unitcost),
            Job_No = sae.ReportEntryCustom5,
            Job_Task_No = sae.ReportEntryCustom6,
            Document_TypeSpecified = true,
            Document_Type = (PurchLines.Document_Type)(Enum.Parse(typeof(PurchLines.Document_Type),"2")),
            Document_No = invno
        };

        piClient.Create(ref line);
        PurchLines.Create_Result result = new PurchLines.Create_Result(line);
        int lin = result.PurchLines.Line_No;
        return lin;
    }

【问题讨论】:

    标签: c# web-services microsoft-dynamics navision dynamics-nav


    【解决方案1】:

    我意识到我没有为joblinetype 分配值,以防它不是“可计费”,因此网络服务无法解析空白字符串

    Job_Line_Type = (PurchLines.Job_Line_Type) (Enum.Parse(typeof (PurchLines.Job_Line_Type), joblinetype)),
    

    【讨论】:

    • 这不会影响答案,但是我遇到了另一个问题,以防有人最终使用它作为参考......在试错编码的混乱中,在某些时候我将 reportid 分配移出 While 循环,这会在 reportID 更改后立即引起问题...string reportid = sae[i].ReportID; 应该在 while 循环内...
    猜你喜欢
    • 2014-07-14
    • 1970-01-01
    • 1970-01-01
    • 2014-03-23
    • 2017-07-13
    • 1970-01-01
    • 2023-03-09
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多