2013-09-23 20 views
1

我在我的Web服務中創建了兩個函數,一個用於獲取所有記錄,另一個用於更新記錄。爲了達到這個目的,我在web服務中使用了數據集(datatable)。如何從提琴手傳遞數據到webservice?

[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。

你可以告訴我怎麼稱呼這個來自提琴手的網絡服務來測試它。無論工作是否正常?

向我推薦任何可用的鏈接或示例代碼。

回答

0

只需將小提琴附加到瀏覽器的進程ID並確保在「文件」菜單下選中「捕獲流量」。

順便說一句。如果你考慮使用AJAX檢索和更新GridView控件,那麼:

  1. 而不是使用ASMX只是把你的網格視圖的UpdatePanel

  2. 而不是使用DataSet作爲參數使用List<MyClass>,其中MyClass定義您的表的數據結構並將響應格式設置爲JSON [ScriptMethod(ResponseFormat = ResponseFormat.Json)]。然後,您需要使用JavaScript構建您的html表格。

您應該使用純JSON作爲客戶端和服務器之間的交換「機制」。