当我在客户端使用WCF服务并尝试使用方法/操作契约时,我的问题在于操作契约中我没有获得相同的方法名称;即我得到带有void返回的“MethodNameAsync”,它应该返回一个/单个Object的列表..
以下是我的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;
}
}
}
答案 0 :(得分:3)
继续发表评论......
Silverlight 仅允许对WCF进行异步调用。因此,对MethodNameAsync
的调用将始终返回void
,因为它不会返回任何内容,而是会在MethodNameCompleted
对应项中返回结果。
这是Silverlight架构中固有的,因为他们希望鼓励保持用户体验流畅,而不是在长时间运行资源(如WCF)时锁定。