这是我创建的Struct类
DocumentBuilderFactory xmlDocFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder xmlDocBuilder = xmlDocFactory.newDocumentBuilder();
System.out.println("**Creating XML File ...");
xmlDocument = xmlDocBuilder.newDocument();
rootElement = xmlDocument.createElement("node");
rootElement.setAttribute("number", wtpart.getNumber());
rootElement.setAttribute("name", wtpart.getName());
xmlDocument.appendChild(rootElement);
Iterator<Integer> iter = alLevel.iterator();
for (int i=1, j=i+1; i<alNumber.size() && i<alName.size() && i<alLevel.size(); i++,j++) {
if (alLevel.get(i) == 1) {
Element element = xmlDocument.createElement("node");
element.setAttribute("number", alNumber.get(i));
element.setAttribute("name", alName.get(i));
rootElement.appendChild(element);
prevElement = element;
}
else if (j<=i) {
if (alLevel.get(j)>alLevel.get(i)){
if (alLevel.get(j) != 1) {
Element element = xmlDocument.createElement("node");
element.setAttribute("number", alNumber.get(i));
element.setAttribute("name", alName.get(i));
prevElement.appendChild(element);
prevElement = element;
}}
else {
Element element = xmlDocument.createElement("node");
element.setAttribute("number", alNumber.get(i));
element.setAttribute("name", alName.get(i));
prevElement.appendChild(element);
}
}
else {
Element element = xmlDocument.createElement("node");
element.setAttribute("number", alNumber.get(i));
element.setAttribute("name", alName.get(i));
prevElement.appendChild(element);
}
}
TransformerFactory transformerFactory = TransformerFactory.newInstance();
Transformer transformer = transformerFactory.newTransformer();
transformer.setOutputProperty(OutputKeys.INDENT, "yes");
transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "2");
DOMSource source = new DOMSource(xmlDocument);
StreamResult result = new StreamResult(new File("E:\\temp", "Test.xml") );
transformer.transform(source, result);
我正在尝试使用此代码,但它只显示1而且只显示最后一个输出
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; }
}
我不确定使用什么代码来获取BStruct中的所有项目。
我也在尝试将webservice用于webservice。提前谢谢〜
答案 0 :(得分: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;
}