【发布时间】:2013-06-14 12:19:14
【问题描述】:
我正在尝试创建一个将返回超过 1 个字符串的 Web 服务。它将返回 4 个字符串。我以前没有 webservices,我过去只返回 true 或 false 值。但现在我需要更多数据。
这是我的网络服务。
[WebMethod]
public string get_currency(string date, string cur_code) {
string rtn = "";
try
{
using (SqlConnection conn = new SqlConnection("Data Source=xxx-xxxxx;Initial Catalog=xxx;Persist Security Info=True;User ID=xxx;Password=xxx"))
{
string selectSql = "select date,code,banknote_buying,banknote_selling from Currencies where date = '" + date + "' and code ='" + cur_code + "'";
SqlCommand comm = new SqlCommand(selectSql, conn);
conn.Open();
SqlDataReader dr = comm.ExecuteReader();
if (dr.Read()) {
rtn = dr["date"].ToString() + dr["code"].ToString() + dr["banknote_buying"].ToString() + dr["banknote_selling"].ToString();
}
}
}
catch (Exception ex)
{
return "Fail";
}
return rtn;
}
我怎样才能将它们作为正确的 SOAP 对象返回
【问题讨论】:
-
用特殊标记分隔字符串,返回字符串数组,构建具有 4 个字符串属性的复合类型等。很多选择。您尝试过什么?
-
这是我在上面尝试过的,@asawyer。我问如何将它作为适当的肥皂对象发送
-
任何可以在soap信封中序列化的东西都是“正确的soap对象” 你还有一个明显的sql注入攻击漏洞。
标签: c# asp.net web-services soap