1

我在我的网络服务中有两个功能,一个用于获取所有记录,另一个用于更新记录。为了实现这一点,我在 Web 服务中使用了数据集(数据表)。

[WebMethod( Description = "Returns Northwind Customers", EnableSession = false )]
  public DataSet GetCustomers()
  {
    SqlDataAdapter custDA = new SqlDataAdapter("SELECT CustomerID, CompanyName FROM Customers", nwindConn);

DataSet custDS = new DataSet();
custDA.MissingSchemaAction = MissingSchemaAction.AddWithKey;
custDA.Fill(custDS, "Customers");

return custDS;
  }

 [WebMethod( Description = "Updates Northwind Customers", EnableSession = false )]
  public DataSet UpdateCustomers(DataSet custDS)
  {
SqlDataAdapter custDA = new SqlDataAdapter();

custDA.InsertCommand = new SqlCommand("INSERT INTO Customers (CustomerID, CompanyName) " +
                                      "Values(@CustomerID, @CompanyName)", nwindConn);
custDA.InsertCommand.Parameters.Add("@CustomerID", SqlDbType.NChar, 5, "CustomerID");
custDA.InsertCommand.Parameters.Add("@CompanyName", SqlDbType.NChar, 15, "CompanyName");

custDA.UpdateCommand = new SqlCommand("UPDATE Customers Set CustomerID = @CustomerID, " +
                                      "CompanyName = @CompanyName WHERE CustomerID = @OldCustomerID", nwindConn);
custDA.UpdateCommand.Parameters.Add("@CustomerID", SqlDbType.NChar, 5, "CustomerID");
custDA.UpdateCommand.Parameters.Add("@CompanyName", SqlDbType.NChar, 15, "CompanyName");
SqlParameter myParm = custDA.UpdateCommand.Parameters.Add("@OldCustomerID", SqlDbType.NChar, 5, "CustomerID");
myParm.SourceVersion = DataRowVersion.Original;

custDA.DeleteCommand = new SqlCommand("DELETE FROM Customers WHERE CustomerID = @CustomerID", nwindConn);
myParm = custDA.DeleteCommand.Parameters.Add("@CustomerID", SqlDbType.NChar, 5, "CustomerID");
myParm.SourceVersion = DataRowVersion.Original;

custDA.Update(custDS, "Customers");

return custDS;
  }

我想从任何其他客户端(不是 net framework )调用这个网络服务,比如 fiddler 或 android 或 php 。

你能告诉我如何从提琴手调用这个网络服务来测试它。它是否工作正常?

建议我任何可用的链接或示例代码。

4

1 回答 1

0

只需将小提琴附加到浏览器的进程 ID 并确保在“文件”菜单下选中“捕获流量”。

顺便提一句。如果您考虑使用 AJAX 检索和更新 GridView,那么:

  1. 而不是使用 ASMX,只需将您的网格视图放到 UpdatePanel

  2. 而不是使用 DataSet 作为参数使用List<MyClass>,其中 MyClass 定义表的数据结构并将响应格式设置为 JSON [ScriptMethod(ResponseFormat = ResponseFormat.Json)]。然后,您需要在 JavaScript 中构建您的 html 表。

您应该使用纯 JSON 作为客户端和服务器之间的交换“机制”。

于 2013-09-23T08:03:09.053 回答