C# Parameter not passed to Web Service

In a revision of the Distributed Application Walkthrough located here: http://msdn2.microsoft.com/en-us/library/1as0t7ff.aspx, we have changed the WinForms app portion of the walkthrough the use the designer tools in VS2005 instead of a manual placement of the datagridview control and the Load/Save buttons.

When we use the VS2005 designer tools to drag and drop from the DataSources window after adding a Web Reference to the project, everything appears to work fine. The Datagridview populates beautifully with the following code in the form class code:

public Form1()
{
InitializeComponent();
localhost.
Service ws = new localhost.Service();
ws.Credentials = System.Net.
CredentialCache.DefaultCredentials;
dataSet1.Customers.Merge(ws.GetCustomers());
}

This brings up the DataGridView populated with the Northwind Customers data table as referenced in the Web Service wsdl, and the DataSet1.xsd, Reference.cs, etc.

Changes are made to the data in the DataGridView, and the save button is clicked to raise the following event and run this code:

private void customersBindingNavigatorSaveItem_Click(object sender, EventArgs e)
{
localhost.
Service ws = new localhost.Service();
ws.Credentials = System.Net.
CredentialCache.DefaultCredentials;
ws.UpdateCustomers(dataSet1.Customers);
}

This method calls the Web Service method located in Service.cs called UpdateCustomers().

[WebMethod]
public void UpdateCustomers(DataSet1.CustomersDataTable customerChanges)
{
myAdapter.Update(customerChanges);
}

During debug, we used the Data Visualizer to view the contents of the parameter in the customersBindingNavigatorSaveItem_Click() method. At the point that the method is called, the dataSet1.Customers parameter is a data table populated with changed data.

When the debugger steps into the Web Service, and the WebMethod UpdateCustomers is called, the parameter customerChanges is EMPTY (no data shown in the Data Visualizer).

Any ideas about why this is happening




Answer this question

C# Parameter not passed to Web Service

  • Binny

    Ok then do the following coding

    [WebMethod]

    public DataSet Update(DataSet ds)

    {

    //your update coding goes here

    return ds;

    }

    in your webservice. Compile it. Update your web reference of your client app.

    then

    localhost.Service sr = new WindowsApplication1.localhost.Service();

    DataSet ds = sr.GetData();

    ds.Tables[0].Rows[0][0] = 2;

    ds = sr.Update( ds );

    Hope this will work. In my end its working fine.

    If this code doesn't work then give me ur mail address I will email my solution to you.



  • iowa242943

    No errors or exceptions are raised. The effect is that no changes are made to the underlying datasource. This makes sense since the datatable that is passed comes into the Service.cs code empty.

    The datatable parameters are properly cast, and no casting exceptions or errors are reported visually or textually during the compile.

    The dataset is empty, so no transaction is attempted in the Service.cs module. The *problem* is that the dataset is populated when passed, and not populated in the receiving parameter in the WebMethod located in Service.cs.



  • murratore

    Try this code. Its working fine....If you want I can send you entire solution

    This is the web service

    [WebMethod]

    public DataSet GetData()

    {

    DataSet ds = new DataSet();

    ds.Tables.Add( new DataTable( "Test" ) );

    ds.Tables[0].Columns.Add (new DataColumn ("IID", System.Type.GetType ("System.String" )));

    DataRow dr = ds.Tables[0].NewRow();

    dr[0] = 1;

    ds.Tables[0].Rows.Add( dr );

    return ds;

    }

    I then add the web referance with a windows application called the GetData methos and got my desired data.

    localhost.Service sr = new WindowsApplication1.localhost.Service();

    DataSet ds = sr.GetData();

    I hope this will work



  • Clester

    Please check your Typed dataset properly casting to Web Service proxy object dataset. Can u send me the error it showing

  • AlexBB

    I am having the same problem. Is this a bug or am I missing something
  • Zadoras

    Thanks for your help and your interest, but the problem is passing the datatable BACK to the webservice with changes.

  • Jim Keifenheim

    Thank you for your suggestion and your help, but I fear you're missing the point.

    The problem is that the strongly-typed dataset.datatable created when using the VS2005 designers (which implements a dataset, bindingsource, and bindingnavigator in the client) creates all of the types for the dataset, their consituent datatables, and the table adapters necessary to create the web service proxy for the client.

    When using those designers, the dataset.datatable type passed as a parameter back to the web service arrives in the web service EMPTY.

    I have no doubt that I can hand-code a solution that works. We do it all the time. That's not the point. The point is that the DESIGNER code doesn't work. I want to know why because it saves a lot of coding time to use it and I would like to.

    That's all.

    Thanks.



  • C# Parameter not passed to Web Service