2017-04-21 22 views
0

This is the SOAP Request使用數組C#asp.net web服務消費

and this is the SOAP Response

這是結構類創建

public struct Biller 
{ 

    public string BillerTag { get; set; } 
    public string Description { get; set; } 
    public string FirstField { get; set; } 
    public string FirstFieldFormat { get; set; } 
    public string FirstFieldWidth { get; set; } 
    public string SecondField { get; set; } 
    public string SecondFieldFormat { get; set; } 
    public string SecondFieldWidth { get; set; } 
    public string ServiceCharge { get; set; } 


} 

我試圖用這個代碼,但它只是顯示在1只最後輸出

[WebMethod(Description = "Retrieves list of available BILLERS for collection as well as other information necessary for the transaction")] 
    public Biller GetBillerList(string AccountID, string UserName, string Password) 
    { 

    ECPNBills.ECPNBillsPaymentService Client = new ECPNBills.ECPNBillsPaymentService(); 
    ECPNBills.BStruct Str = new ECPNBills.BStruct(); 


     Biller Bil = new Biller(); 

     Str = Client.GetBillerList(AccountID, UserName, Password); 


     foreach (ECPNBills.BStruct cd in Client.GetBillerList(AccountID, UserName, Password)) 
     { 
      Bil.BillerTag = cd.BillerTag; 
      Bil.Description = cd.Description; 
      Bil.FirstField = cd.FirstField; 
      Bil.FirstFieldFormat = cd.FirstFieldFormat; 
      Bil.FirstFieldWidth = cd.FirstFieldWidth; 
      Bil.SecondField = cd.SecondField; 
      Bil.SecondFieldFormat = cd.SecondFieldFormat; 
      Bil.SecondFieldWidth = cd.SecondFieldWidth; 
      Bil.ServiceCharge = cd.ServiceCharge; 

     } 

     return Bil; 



    } 

我不確定要使用哪些代碼才能從BStruct獲得所有物品。

我也試圖使用web服務web服務。預先感謝您〜

回答

0

將您的方法的return type更改爲List<Biller>

[WebMethod(Description = "Retrieves list of available BILLERS for collection as well as other information necessary for the transaction")] 
public List<Biller> GetBillerList(string AccountID, string UserName, string Password) 
{ 

    ECPNBills.ECPNBillsPaymentService Client = new ECPNBills.ECPNBillsPaymentService(); 
    ECPNBills.BStruct Str = new ECPNBills.BStruct(); 


    List<Biller> BilList = new List<Biller>(); 

    Str = Client.GetBillerList(AccountID, UserName, Password); 


    foreach (ECPNBills.BStruct cd in Client.GetBillerList(AccountID, UserName, Password)) 
    { 
     Biller Bil = new Biller(); 

     Bil.BillerTag = cd.BillerTag; 
     Bil.Description = cd.Description; 
     Bil.FirstField = cd.FirstField; 
     Bil.FirstFieldFormat = cd.FirstFieldFormat; 
     Bil.FirstFieldWidth = cd.FirstFieldWidth; 
     Bil.SecondField = cd.SecondField; 
     Bil.SecondFieldFormat = cd.SecondFieldFormat; 
     Bil.SecondFieldWidth = cd.SecondFieldWidth; 
     Bil.ServiceCharge = cd.ServiceCharge; 

     BilList.Add(Bil); 
    } 

    return BilList; 

} 
+0

它的工作!謝謝 –