我正在尝试在我的 WCF 服务中创建一个异步方法,但我收到了上述主题错误消息。我只是想返回一个类别列表。
为了清楚起见,在最后的上述错误消息中添加以下内容:YeagerTechModel.Category[]
wcfclient 服务已成功添加,但此方法除外(旁边有一个红色的“X”)。实际上,所有方法(在 wcf 服务客户端中)都需要一个关联的异步方法(带有红色“X”)以及其他常规同步方法。
我知道如何使用 WCF,但不是这方面的专家。我需要做什么才能使其正常运行?
我正在使用 VisualStudio 2013 的完整发布版本,并且该项目使用 4.5.1 框架。我也在使用 EntityFramework 6。
我的服务合同包含以下命名空间。
using System.Threading.Tasks;
我的经营合同如下。
[OperationContract(Name="GetCategoriesAsync")]
Task<List<Category>> GetCategoriesAsync();
我的数据合同如下:
namespace YeagerTechModel
{
using System;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.Collections.Generic;
[Serializable, DataContract(IsReference = true)]
public partial class Category
{
public Category()
{
this.Projects = new HashSet<Project>();
}
[DataMember]
public short CategoryID { get; set; }
[DataMember]
public string Description { get; set; }
[DataMember]
public virtual ICollection<Project> Projects { get; set; }
}
}
我的网络服务中的方法如下。请注意,我没有任何设计时编译错误,并且能够成功构建解决方案:
public async Task<List<Category>> GetCategoriesAsync()
{
try
{
using (YeagerTechEntities DbContext = new YeagerTechEntities())
{
DbContext.Configuration.ProxyCreationEnabled = false;
DbContext.Database.Connection.Open();
var category = await DbContext.Categories.ToListAsync();
return category;
}
}
catch (Exception ex)
{
throw ex;
}
}