简体   繁体   English

Web服务的更改未反映在客户端上吗?

[英]Changes in webservice are not reflected at the client?

I'm using a WCF-webservice and Linq-To-SQL to insert a new record. 我正在使用WCF-webservice和Linq-To-SQL插入新记录。

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. 但是,在Web服务中,我设置了两个字段CreatedByCreated ,但是即使我使用ref参数(如MSDN上的建议),更改也不会反映在客户端上。 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 : 这将在以后引起问题,例如,如果我尝试将其删除,则由于这些db.SubmitChanges() non-nulldb.SubmitChanges()处将出现以下异常:

System.Data.SqlTypes.SqlTypeException: SqlDateTime overflow. System.Data.SqlTypes.SqlTypeException:SqlDateTime溢出。 Must be between 1/1/1753 12:00:00 AM and 12/31/9999 11:59:59 PM. 必须介于1/1/1753 12:00:00 AM和12/31/9999 11:59:59 PM之间。

Here's the insert method at the client(winforms application): 这是客户端(winforms应用程序)上的insert方法:

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: 这是webservice方法:

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). 我的wcf,winforms和linq-to-sql技能很生锈(这就是我选择它们的原因)。

You can't pass by reference in a web service. 您不能在Web服务中通过引用传递。 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();
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM