我正在尝试使用生成的代理从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;
}
我发现“Event”参数设置为新的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");
}
}
}
}
答案 0 :(得分:3)
几个问题:
更新1:您可以与我们分享BCL.BusinessObjects.EventWrapper的来源吗?
更新2: EventWrapper类的那些自定义构造函数对我来说很可疑,因为在客户端上,EventWrapper应该由Service Reference生成,因此不应包含这些构造函数。所以你在客户端上修改了Reference.cs - 你不应该做的事情,或者你以某种方式从服务器端代码中导入了代码 - 这是你不应该做的事情。哪一个?
答案 1 :(得分:0)
您能否先使用WCFTestClient或SoapUI尝试使用Web服务?它可能是服务器端正在起作用。
另外,我更喜欢合同分享。这样就可以解决更少的问题,因为您不需要生成这些服务引用。