如何在C#中调用此方法以从WS返回数据

时间:2018-12-05 10:47:59

标签: c#

我是C#的初学者。我想开发一个简单的应用程序来从WS检索数据。我在下面有此方法,但是我不知道如何在main方法中调用它以便从WS返回值。

public static P6WSStubs.Ws.P6.WBS.WBS[] ReadWbs(string WbsIdListFilter)
    {
        PrimaveraService.HostName = "xxx.xx.xxx.xxx";
        PrimaveraService.Port = "8206";
        PrimaveraService.HTTP = "http://";
        WBSFieldType[] wbsFieldTypeArray = new WBSFieldType[17] { WBSFieldType.ObjectId, WBSFieldType.Code, WBSFieldType.Name, WBSFieldType.ProjectObjectId, WBSFieldType.ParentObjectId, WBSFieldType.SummaryPlannedStartDate, WBSFieldType.SummaryPlannedFinishDate, WBSFieldType.SummaryActualStartDate, WBSFieldType.SummaryActualFinishDate, WBSFieldType.SummaryDurationPercentComplete, WBSFieldType.SummaryUnitsPercentComplete, WBSFieldType.SummaryPerformancePercentCompleteByCost, WBSFieldType.SummaryRemainingTotalCost, WBSFieldType.SummaryEarnedValueByCost, WBSFieldType.SummaryPlannedCost, WBSFieldType.SummaryBudgetAtCompletionByCost, WBSFieldType.SummaryEstimateAtCompletionByCost };
        ReadWBS ReadWBS1 = new ReadWBS();
        ReadWBS1.Field = wbsFieldTypeArray;
        ReadWBS1.Filter = "ObjectId IN (" + WbsIdListFilter + ")";
        WBSService wbsService = new WBSService();
        wbsService.Url = HTTP + HostName + ":" + Port + "/p6ws/services/WBSService";
        wbsService.Timeout = 6000000;
        wbsService.CookieContainer = PrimaveraService.cookieContainer;
        return wbsService.ReadWBS(ReadWBS1);

    }

我应该如何调用此方法以便从WS接收值? 很抱歉这个愚蠢的问题。

1 个答案:

答案 0 :(得分:1)

我假设您的ReadWbs和Main方法都在同一类中,在这种情况下,您的代码应类似于以下内容(方法的顺序可能不同,没关系):

public static P6WSStubs.Ws.P6.WBS.WBS[] ReadWbs(string WbsIdListFilter)
{
   //Same as above
}

public static void Main(string[] args)
{
    string wbsIdListFilter = "<Your Filter Here>";
    P6WSStubs.Ws.P6.WBS.WBS[] result = ReadWbs(wbsIdListFilter);
    //...
}