0

当我在客户端使用 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;
        }
    }
}
4

1 回答 1

3

继我的评论...

Silverlight只允许异步调用 WCF。因此,对 的调用MethodNameAsync将始终返回void ,因为它不返回任何内容,而是在MethodNameCompleted对应方中返回结果。

这是 Silverlight 架构中固有的,因为他们希望鼓励在制作 WCF 等长时间运行的资源时保持用户体验流畅而不是锁定。

于 2013-05-09T10:52:34.537 回答