我创建了自己的 Web 服务来使用。我添加了服务参考。但是在 store_getProducts 处,XDocument xReturn = XDocument.Load(e.Result); 发生错误 它说该字符串未被识别为有效的uri。参数名称 inputuri。有人可以告诉我有什么问题吗
SvcRefstore.ServiceSoapClient storeclient = new SvcRefstore.ServiceSoapClient();
storeclient.getProductsAllCompleted += new EventHandler<SvcRefstore.getProductsAllCompletedEventArgs>(store_getProducts);
storeclient.getProductsAllAsync();
storeclient.setItemsarrayAsync(itemarray);
store_getProducts
void store_getProducts(object sender, SvcRefstore.getProductsAllCompletedEventArgs e)
{
XDocument xReturn = XDocument.Load(e.Result);
IEnumerable<Products> myQuote = from item in xReturn.Descendants("Products")
select new Products
{
Name = Convert.ToString(item.Element("Name").Value),
unitPrice = Convert.ToString(item.Element("unitPrice").Value),
};
Products thisQuote = myQuote.ElementAt(0);
textBlock1.Text = thisQuote.Name.ToString();
}
下面是我创建消费的 getProducts 方法
public string getProductsAll()
{
storeDBCon dbConn;
dbConn = new storeDBCon();
DataSet idataset = new DataSet();
string products = "";
SqlConnection db = dbConn.GetConnection();
SqlCommand cmd;
string sqlRetrieve = "SELECT * FROM Product WHERE Name = @Name";
db.Open();
try
{
for (int i = 0; i < itemsarray.Length; i ++ )
// foreach (String item in itemsarray)
{
cmd = new SqlCommand(sqlRetrieve, db);
cmd.Parameters.AddWithValue("@Name", itemsarray[i]);
SqlDataReader reader = cmd.ExecuteReader();
if (reader.HasRows == true)
{
reader.Read();
//_userId = reader.GetInt32(0);
productID = reader.GetInt32(0);
pname = reader.GetString(1);
pDesc = reader.GetString(2);
unitPrice = reader.GetString(3);
imagefilename = reader.GetString(4);
products = productID + "," +pname + "," + pDesc + "," + unitPrice + "," + imagefilename + "";
}
else
products = "Null";
}
}
catch (Exception ex)
{
errMsg = ex.Message;
}
finally
{
db.Close();
}
return products;
}
下面是 setItemsarray 方法
public void setItemsarray(string[] _str)
{
itemsarray = _str;
}