【问题标题】:Consuming webservices with arrays c# asp.net使用数组 c# asp.net 使用 web 服务
【发布时间】:2017-04-21 06:56:42
【问题描述】:

这是我创建的 Struct 类

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 中获取所有项目。

我也在尝试使用 webservice 到 webservice。先谢谢啦~

【问题讨论】:

    标签: c# asp.net web-services soap


    【解决方案1】:

    将您的方法的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;
    
    }
    

    【讨论】:

      猜你喜欢
      • 2013-02-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-05-22
      • 1970-01-01
      • 2015-11-05
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多