WCF操作契约在应该返回List时返回void
本文关键字:返回 Objects void List WCF 契约 操作 | 更新日期: 2023-09-27 18:12:44
我的问题是在操作合同,当我在客户端消费WCF服务,并尝试使用方法/操作合同,我没有得到相同的方法名称;也就是说,我得到"MethodNameAsync"与void返回,它应该返回一个列表/单个对象(s)..
编辑:
我的客户端/消费者是一个silverlight应用程序
这是我的WCF的代码示例
[ServiceContract]
public interface ICRUDManagerService
{
[OperationContract]
List<MyCustomObject> GetAllCustomObjects();
}
public class CRUDManagerService : ICRUDManagerService
{
public List<MyCustomObject> GetAllCustomObjects()
{
return MyCustomObject.GetAllCustomObjects();
}
}
[DataContract]
public class MyCustomObject:INotifyPropertyChanged
{
#region [ Public Properties and their Private Fields ]
private Int32 _iSerial;
[DataMember]
public Int32 iSerial
{
get
{
return this._iSerial;
}
set
{
if (value != this._iSerial)
{
this._iSerial = value;
RaisePropertyChanged("iSerial");
}
}
}
private string _code;
[DataMember]
public String Code
{
get
{
return this._code;
}
set
{
if (value != this._code)
{
this._code = value;
RaisePropertyChanged("Code");
}
}
}
private string _ename;
[DataMember]
public String Ename
{
get
{
return this._ename;
}
set
{
if (value != this._ename)
{
this._ename = value;
RaisePropertyChanged("Ename");
}
}
}
private string _aname;
[DataMember]
public String Aname
{
get
{
return this._aname;
}
set
{
if (value != this._aname)
{
this._aname = value;
RaisePropertyChanged("Aname");
}
}
}
private Int32? _defaultRoutID;
[DataMember]
public Int32? DefaultRoutID
{
get
{
return this._defaultRoutID;
}
set
{
if (value != this._defaultRoutID)
{
this._defaultRoutID = value;
RaisePropertyChanged("DefaultRoutID");
}
}
}
#endregion [ End of Public Properties ]
#region Implement INotifyPropertyChanged
public event PropertyChangedEventHandler PropertyChanged;
public void RaisePropertyChanged(string propertyName)
{
PropertyChangedEventHandler handler = PropertyChanged;
if (handler != null) handler(this, new PropertyChangedEventArgs(propertyName));
}
#endregion
public static MyCustomObject GetDTOFromDALObject(CustomeEntites.Model.MyEntityObject src)
{
MyCustomObject obj = new MyCustomObject();
obj.iSerial = src.iSerial;
obj.Code = src.Code;
obj.Ename = src.Ename;
obj.Aname = src.Aname;
obj.DefaultRoutID = src.DefaultRoutID;
return obj;
}
public CustomeEntites.Model.MyEntityObject GetDALObject()
{
CustomeEntites.Model.MyEntityObject obj = new CustomeEntites.Model.MyEntityObject();
obj.iSerial = iSerial;
obj.Code = Code;
obj.Ename = Ename;
obj.Aname = Aname;
obj.DefaultRoutID = DefaultRoutID;
return obj;
}
static public List<MyCustomObject> GetAllCustomObjects()
{
using (CustomeDBEntites context = new CustomeDBEntites ())
{
List<WF_MyCustomObject> _ReturnableList = new List<WF_MyCustomObject>();
foreach (MyEntityObject item in context.MyEntityObject.ToList())
{
_ReturnableList.Add(GetDTOFromDALObject(item, false));
}
return _ReturnableList;
}
}
}
继我的评论之后…
Silverlight只允许异步调用WCF。因此,对MethodNameAsync
的调用将始终返回void
,因为它不返回任何东西,相反,结果将在MethodNameCompleted
对应中返回。
这是Silverlight架构中固有的,因为他们希望在创建WCF等长时间运行的资源时保持用户体验的流畅性,而不是锁定。