>我在我的Web服务中做了两个函数,一个用于获取所有记录,第二个用于更新记录。为了实现这一点,我在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服务,例如小提琴手或Android或php。
你能告诉我如何从小提琴手调用这个网络服务进行测试吗?是否工作正常?
向我建议任何可用的链接或示例代码。
只需将小提琴附加到浏览器的进程 ID 上,并确保在"文件"菜单下选中"捕获流量"。
顺便说一句。如果考虑使用 AJAX 检索和更新 GridView,请执行以下任一操作:
-
无需使用 ASMX,只需将网格视图放入 UpdatePanel 即可
-
不要使用数据集作为参数,请使用
List<MyClass>
,其中MyClass定义表的数据结构并将响应格式设置为JSON[ScriptMethod(ResponseFormat = ResponseFormat.Json)]
。然后你需要用JavaScript构建你的html表。
您应该使用纯 JSON 作为客户端和服务器之间的交换"机制"。