Tim Schmelter
Tim Schmelter

Reputation: 460228

Changes in webservice are not reflected at the client?

I'm using a WCF-webservice and Linq-To-SQL to insert a new record.

However, in the webservice i'm setting two fields, CreatedBy and Created, but even if i use ref parameter(as suggested on MSDN) the changes are not reflected at the client. So when i debug the service the properties are set and the record is inserted correctly, but at the calling method the object's properties are still unset.

This will cause problems later, for example if i'll try to delete it i'll get following exception at db.SubmitChanges() since these columns are non-null:

System.Data.SqlTypes.SqlTypeException: SqlDateTime overflow. Must be between 1/1/1753 12:00:00 AM and 12/31/9999 11:59:59 PM.

Here's the insert method at the client(winforms application):

private void Add_Status()
{
    using (var db = new ERP_ServiceClient())
    {
        var status = new Erp_ServiceReference.Status();
        status.Name = this.txtStatusNameAdd.Text;
        db.InsertStatus(status, this.IdUser);
        statusBindingSource.Add(status);
    }

    this.txtStatusNameAdd.Text = "";
    this.txtStatusNameAdd.Select();
}

This is the webservice method:

public void InsertStatus(ref Status status, int userID)
{
    using (var db = new ERPDataContext())
    {
        status.CreatedBy = userID;
        status.Created = DateTime.Now;
        db.Status.InsertOnSubmit(status);
        db.SubmitChanges();
    }
}

What am i doing wrong? My wcf,winforms and linq-to-sql skills are rusty(that's why i've chosen them).

Upvotes: 0

Views: 274

Answers (1)

Rob
Rob

Reputation: 5588

You can't pass by reference in a web service. You can return the value.

public Status InsertStatus(Status status, int userID)
{
    using (var db = new ERPDataContext())
    {
        status.CreatedBy = userID;
        status.Created = DateTime.Now;
        db.Status.InsertOnSubmit(status);
        db.SubmitChanges();
        return status;
    }
}

private void Add_Status()
{
    using (var db = new ERP_ServiceClient())
    {
        var status = new Erp_ServiceReference.Status();
        status.Name = this.txtStatusNameAdd.Text;
        status = db.InsertStatus(status, this.IdUser);
        statusBindingSource.Add(status);
    }

    this.txtStatusNameAdd.Text = "";
    this.txtStatusNameAdd.Select();
}

Upvotes: 1

Related Questions