gpt4 book ai didi

.net - 从 Silverlight : Somewhere my parameters are disappearing 调用 WCF 服务

转载 作者:行者123 更新时间:2023-12-04 06:18:41 27 4
gpt4 key购买 nike

我正在尝试使用生成的代理从 Silverlight 调用 WCF 服务,但由于某种原因,我的参数被清空了。我这样打电话:

Events.EventServiceClient events = new Events.EventServiceClient(new BasicHttpBinding(),     new EndpointAddress("http://localhost:52878/EventService.svc"));
event.EventTypeName = e.GetType().FullName;
events.AddEventWrapperAsync(new EventWrapper(event));

在调试时,当我调用 AddEventWrapperAsync 方法时,我看到我有一个有效的对象。但是,进入下一个调用
public System.IAsyncResult BeginAddEventWrapper(BCL.BusinessObjects.EventWrapper Event, System.AsyncCallback callback, object asyncState) {
object[] _args = new object[1];
_args[0] = Event;
System.IAsyncResult _result = base.BeginInvoke("AddEventWrapper", _args, callback, asyncState);
return _result;
}

我发现“事件”参数设置为新的 EventWrapper(即所有字段都设置为其默认值)。

有谁知道从哪里开始寻找?这显然是一个序列化问题,但除此之外我很困惑。

更新 : 这是 EventWrapper
using System;
using System.Collections.Generic;
using BCL.FLY;
using BCL.CTB;
using BCL.WCN;
using BCL;
using System.ServiceModel;
using System.Runtime.Serialization;
namespace BCL.BusinessObjects
{
[Serializable]
[DataContract]
public class Point
{
[DataMember]
public Double X { get; set; }
[DataMember]
public Double Y { get; set; }
public Point(System.Windows.Point point){
this.X = point.X;
this.Y = point.Y;
}
}
[DataContract]
public class EventWrapper
{
[DataMember]
public Guid Id { get; set; }
[DataMember]
public string StudentID{get;set;}
[DataMember]
public DateTime LocalTimestamp{get;set;}
[DataMember]
public GameEventType Type { get; set; }
[DataMember]
public int Level { get; set; }
[DataMember]
public int Score { get; set; }
[DataMember]
public string message { get; set; }
[DataMember]
public EventLoggingLevel LogLevel { get; set; }
[DataMember]
public int SessionID { get; set; }
[DataMember]
public string EventTypeName { get; set; }
[DataMember]
public double Speed { get; set; }
[DataMember]
public GameEventSubtype SubType { get; set; }


//CTBEvent
[DataMember]
public double BallSize{get;set;}
[DataMember]
public string CTBRuleType{get;set;}
[DataMember]
public Point ClickLocation{get;set;}
[DataMember]
public TimeSpan StimulusDuration{get;set;}
[DataMember]
public List<BallInfo> BallStates{get;set;}

//FLYEvent
[DataMember]
public string Category{get;set;}
[DataMember]
public List<BflyInfo> ButterFlies{get;set;}

//WCNEvent
[DataMember]
public TimeSpan TimeGiven{get;set;}
[DataMember]
public TimeSpan TimeRemaning{get;set;}
[DataMember]
public WCNTrialData TrialData{get;set;}


#region constructors

public EventWrapper() { }

public EventWrapper(IGameEvent _event)
{
this.StudentID = _event.StudentID;
this.LocalTimestamp = _event.LocalTimestamp;
this.Type = _event.Type;
this.Level = _event.Level;
this.Score = _event.Score;
this.message = _event.message;
this.LogLevel = _event.LogLevel;
this.SessionID = _event.SessionID;
this.EventTypeName = _event.EventTypeName;
this.Speed = _event.Speed;
this.SubType = _event.SubType;
}

public EventWrapper(CTBEvent _event)
{
this.StudentID = _event.StudentID;
this.LocalTimestamp = _event.LocalTimestamp;
this.Type = _event.Type;
this.Level = _event.Level;
this.Score = _event.Score;
this.message = _event.message;
this.LogLevel = _event.LogLevel;
this.SessionID = _event.SessionID;
this.EventTypeName = _event.EventTypeName;
this.Speed = _event.Speed;
this.SubType = _event.SubType;
this.BallSize = _event.BallSize;
this.CTBRuleType = _event.CTBRuleType;
this.ClickLocation = new Point(_event.ClickLocation);
this.StimulusDuration = _event.StimulusDuration;
this.BallStates = _event.BallStates;
}

public EventWrapper(FLYEvent _event)
{
this.StudentID = _event.StudentID;
this.LocalTimestamp = _event.LocalTimestamp;
this.Type = _event.Type;
this.Level = _event.Level;
this.Score = _event.Score;
this.message = _event.message;
this.LogLevel = _event.LogLevel;
this.SessionID = _event.SessionID;
this.EventTypeName = _event.EventTypeName;
this.Speed = _event.Speed;
this.SubType = _event.SubType;
this.Category = _event.Category;
this.ButterFlies = _event.ButterFlies;
}

public EventWrapper(WCNEvent _event)
{
this.StudentID = _event.StudentID;
this.LocalTimestamp = _event.LocalTimestamp;
this.Type = _event.Type;
this.Level = _event.Level;
this.Score = _event.Score;
this.message = _event.message;
this.LogLevel = _event.LogLevel;
this.SessionID = _event.SessionID;
this.EventTypeName = _event.EventTypeName;
this.Speed = _event.Speed;
this.SubType = _event.SubType;
this.TimeGiven = _event.TimeGiven;
this.TimeRemaning = _event.TimeRemaning;
this.TrialData = _event.TrialData;
}

#endregion
}

}

这是我选择“添加服务引用”时生成的事件
public partial class CTBEvent : BCL.WCFEvents.IGameEvent {

private double BallSizeField;

private System.Collections.ObjectModel.ObservableCollection<BCL.WCFEvents.BallInfo> BallStatesField;

private string CTBRuleTypeField;

private System.Windows.Point ClickLocationField;

private System.TimeSpan StimulusDurationField;

private System.Collections.ObjectModel.ObservableCollection<string> _tField;

[System.Runtime.Serialization.DataMemberAttribute()]
public double BallSize {
get {
return this.BallSizeField;
}
set {
if ((this.BallSizeField.Equals(value) != true)) {
this.BallSizeField = value;
this.RaisePropertyChanged("BallSize");
}
}
}

[System.Runtime.Serialization.DataMemberAttribute()]
public System.Collections.ObjectModel.ObservableCollection<BCL.WCFEvents.BallInfo> BallStates {
get {
return this.BallStatesField;
}
set {
if ((object.ReferenceEquals(this.BallStatesField, value) != true)) {
this.BallStatesField = value;
this.RaisePropertyChanged("BallStates");
}
}
}

[System.Runtime.Serialization.DataMemberAttribute()]
public string CTBRuleType {
get {
return this.CTBRuleTypeField;
}
set {
if ((object.ReferenceEquals(this.CTBRuleTypeField, value) != true)) {
this.CTBRuleTypeField = value;
this.RaisePropertyChanged("CTBRuleType");
}
}
}

[System.Runtime.Serialization.DataMemberAttribute()]
public System.Windows.Point ClickLocation {
get {
return this.ClickLocationField;
}
set {
if ((this.ClickLocationField.Equals(value) != true)) {
this.ClickLocationField = value;
this.RaisePropertyChanged("ClickLocation");
}
}
}

[System.Runtime.Serialization.DataMemberAttribute()]
public System.TimeSpan StimulusDuration {
get {
return this.StimulusDurationField;
}
set {
if ((this.StimulusDurationField.Equals(value) != true)) {
this.StimulusDurationField = value;
this.RaisePropertyChanged("StimulusDuration");
}
}
}

[System.Runtime.Serialization.DataMemberAttribute()]
public System.Collections.ObjectModel.ObservableCollection<string> _t {
get {
return this._tField;
}
set {
if ((object.ReferenceEquals(this._tField, value) != true)) {
this._tField = value;
this.RaisePropertyChanged("_t");
}
}
}
}

最佳答案

几个问题:

  • 可能与问题无关,但为什么您使用“事件”等保留关键字作为变量名?
  • 您已经调试了服务器端并验证了参数修改确实发生并且不仅仅是调试 View 的问题,对吗?
  • 是什么让您认为这是一个序列化问题?从我读过的内容来看,还没有发生序列化。
  • 您确定生成的代理/客户端代码与 匹配吗?当前 托管在 http://localhost:52878/EventService.svc 的服务版本
  • 更新 : 只是在黑暗中拍摄。使用 Begin/End 方法调用方法有什么不同吗? (我知道不应该)

  • 更新 1:您能否与我们分享 BCL.BusinessObjects.EventWrapper 的源代码?

    更新 2: EventWrapper 类的那些自定义构造函数在我看来很可疑,因为在客户端上 EventWrapper 应该由服务引用生成,因此不应该包含这些构造函数。所以你要么在客户端修改了 Reference.cs——你不应该做的事情,或者你以某种方式从服务器端代码导入了代码——你也不应该做的事情。哪一个?

    关于.net - 从 Silverlight : Somewhere my parameters are disappearing 调用 WCF 服务,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6875166/

    27 4 0