请求类结构:
public class QueryParams {
public List<QueryParam> QueryParam { get; set; }
}
public class QueryParam {
public string Parameter { get; set; }
}
服务期望以下格式:
<typ:queryParams>
<typ:queryParam>
<typ:parameter>BUSINESS_CATEGORY</typ:parameter>
</typ:queryParam>
<typ:queryParam>
<typ:parameter>CATEGORY</typ:parameter>
</typ:queryParam>
</typ:queryParams>
我如何形成请求?
答案 0 :(得分:0)
using QueryParams = System.Collections.Generic.List<QueryParam>;
public class QueryParam {
public string Parameter { get; set; }
public QueryParam(string para) {
Parameter = para;
}
}
public class Program
{
public static void Main()
{
var Qp = new QueryParams() {
new QueryParam("BUSINESS_CATEGORY"),
new QueryParam("CATEGORY")
};
string QpXml = ToXml(Qp);
// Use your XML from here on
}
private static string ToXml(QueryParams Qp) {
StringBuilder Sb = new StringBuilder();
Sb.AppendLine("<typ:queryParams>");
foreach (var q in Qp) {
Sb.AppendLine("<typ:queryParam>");
Sb.AppendLine("<typ:parameter>" + q.Parameter + "</typ:parameter>");
Sb.AppendLine("</typ:queryParam>");
}
Sb.AppendLine("</typ:queryParams>");
return Sb.ToString();
}
}