【发布时间】:2010-12-27 00:26:08
【问题描述】:
我正在尝试开发一个具有 2 层的系统:移动客户端和使用 LINQ to SQL 将信息存储在数据库中的服务器。 我想创建一个 WCF 服务器,在服务器中存储一个任务,所以它会从客户端接收一个任务,并使用 LINQ to SQL 来存储它。
为了完成这项服务,我创建了 dbml 文件,因此我可以使用数据上下文。
这是我的服务方式:
public Task SaveTask(string token, Task task)
{
TrackingDataContext dataConext = new TrackingDataContext();
//Saves/Updates the task
dataConext.Tasks.InsertOnSubmit(task);
dataConext.SubmitChanges();
return task;
}
令牌将在未来使用
这是我的客户端方法,它将调用服务:
private void btnSave_Click(object sender, EventArgs e)
{
//Populate the object with the info
Task task = new Task();
task.Title = tbTitle.Text;
task.Description = tbDescription.Text;
//this is a FK to another table
task.Severity = ((Severity)lbSeverities.SelectedItem);
//the first state: "open"
task.StateID = 1;
//Save the task
client.SaveTaskCompleted += new EventHandler<SaveTaskCompletedEventArgs>(client_SaveTaskCompleted);
client.SaveTaskAsync(App.Token, task);
}
如您所见,我正在创建一个新对象,填充它并将其发送到我的服务,该服务将获取并存储它。理论上是可以的。
客户端能够创建对象并发送到服务器。 当服务器收到请求时,它尝试再次构建对象,但随后我在此方法中得到一个 System.Data.Linq.ForeignKeyReferenceAlreadyHasValueException(从 VS2010 自动创建):
[global::System.Data.Linq.Mapping.ColumnAttribute(Storage="_SeverityID", DbType="Int NOT NULL")]
public int SeverityID
{
get
{
return this._SeverityID;
}
set
{
if ((this._SeverityID != value))
{
if (this._Severity.HasLoadedOrAssignedValue)
{
throw new System.Data.Linq.ForeignKeyReferenceAlreadyHasValueException();
}
this.OnSeverityIDChanging(value);
//The exception happens in this line
this.SendPropertyChanging();
this._SeverityID = value;
this.SendPropertyChanged("SeverityID");
this.OnSeverityIDChanged();
}
}
}
我的服务器方法不可能有任何错误,因为: 1-非常简单,里面没有逻辑 2-我什至无法调试它,错误发生在我的方法被调用之前,可能是在解组请求时。
这样的事情会发生什么?我在哪里可以看看?会不会是配置问题?
谢谢你, 奥斯卡
编辑:找到这个链接Serializing Linq2Sql over Wcf - bug or misunderstanding?,他们告诉这是一个错误,但它是一年前的。有谁知道解决了吗?
【问题讨论】:
标签: silverlight wcf web-services linq-to-sql windows-phone-7