当我在客户端使用 WCF 服务并尝试使用方法/操作合同时,我的问题在于操作合同我没有得到相同的方法名称;即我得到带有无效返回的“MethodNameAsync”,它应该返回一个/单个对象列表..
编辑:
我的客户/消费者是一个 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;
}
}
}