如何从fiddler传递数据到webservice?

时间:2013-09-23 07:41:00

标签: asp.net web-services fiddler

我在我的网络服务中创建了两个函数,一个用于获取所有记录,另一个用于更新记录。为了实现这一点,我在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;
  }

我想从任何其他客户端(非网络框架)调用此Web服务,例如fiddler或android或php。

你能告诉我如何从fiddler调用这个web服务来测试它。是否工作正常?

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

1 个答案:

答案 0 :(得分:0)

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

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

  1. 不要使用ASMX,只需将网格视图放到UpdatePanel

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

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

相关问题