WCF服务库
我是WCF服务的新手。我被要求手动创建WCF服务。我做了以下工作:WCF服务库,wcf,Wcf,我是WCF服务的新手。我被要求手动创建WCF服务。我做了以下工作: 创建了一个新的项目控制台应用程序 创建了一个名为Evaluation 创建了一个名为IEEvaluatorService 创建了一个类EvaluationService实现接口ieevaluatorservice 我需要使用以下地址:http://localhost:8000/Evaluations然后通过WcfTestClient测试我的服务。我不知道下一步该怎么办。代码如下 提前感谢您的帮助 namespace Evalua
Evaluation
IEEvaluatorService
EvaluationService
实现接口ieevaluatorservice
http://localhost:8000/Evaluations
然后通过WcfTestClient测试我的服务。我不知道下一步该怎么办。代码如下
提前感谢您的帮助
namespace Evaluations
{
[ServiceContract]
interface IEvaluatorService
{
[OperationContract(Name="AddEvaluation")]
int Add(string user, string content);
[OperationContract(Name="RemoveEvaluation")]
void Remove([MessageParameter(Name="existingID")] int id);
[OperationContract(Name="GetAllEvaluations")]
Evaluation[] GetAll();
[OperationContract(Name="GetEvaluation")]
Evaluation Get(int id);
[OperationContract(Name="GetAllEvaluationsFrom")]
Evaluation[] GetAll([MessageParameter(Name = "username")] string submitter);
}
}
namespace Evaluations
{
class EvaluationService : IEvaluatorService
{
List<Evaluation> myList = new List<Evaluation>();
static int count = 0;
public int Add(string user, string content)
{
Evaluation eval = new Evaluation()
{
UniqueID = count++,
Submitter = user,
SubmissionTime = DateTime.Now,
Text = content
};
myList.Add(eval);
return eval.UniqueID;
}
public void Remove(int id)
{
myList.RemoveAt(id);
}
public Evaluation[] GetAll()
{
return myList.ToArray<Evaluation>();
}
public Evaluation Get(int id)
{
throw new NotImplementedException();
}
public Evaluation[] GetAll(string submitter)
{
throw new NotImplementedException();
}
}
}
namespace Evaluations
{
[DataContract]
class Evaluation
{
[DataMember]
public string Submitter { get; set; }
[DataMember]
public int UniqueID { get; set; }
[DataMember]
public DateTime SubmissionTime { get; set; }
[DataMember]
public string Text { get; set; }
}
}
名称空间求值
{
[服务合同]
接口评估服务
{
[运营合同(Name=“AddEvaluation”)]
int Add(字符串用户、字符串内容);
[运营合同(Name=“RemoveEvaluation”)]
作废删除([MessageParameter(Name=“existingID”)]int-id);
[运营合同(Name=“GetAllEvaluations”)]
Evaluation[]GetAll();
[运营合同(Name=“GetEvaluation”)]
评估获取(int-id);
[运营合同(Name=“GetAllEvaluationsFrom”)]
评估[]GetAll([MessageParameter(Name=“username”)]字符串提交者);
}
}
名称空间求值
{
类评估服务:IEEvaluatorService
{
List myList=新列表();
静态整数计数=0;
公共整数添加(字符串用户、字符串内容)
{
评估eval=新评估()
{
UniqueID=count++,
提交者=用户,
SubmissionTime=日期时间。现在,
文本=内容
};
myList.Add(eval);
返回eval.UniqueID;
}
公共无效删除(int id)
{
myList.RemoveAt(id);
}
公共评估[]获取全部()
{
返回myList.ToArray();
}
公共评估获取(int-id)
{
抛出新的NotImplementedException();
}
公共评估[]GetAll(字符串提交者)
{
抛出新的NotImplementedException();
}
}
}
名称空间求值
{
[数据合同]
课堂评价
{
[数据成员]
公共字符串提交者{get;set;}
[数据成员]
public int UniqueID{get;set;}
[数据成员]
公共日期时间提交时间{get;set;}
[数据成员]
公共字符串文本{get;set;}
}
}
最简单的方法是
- 进入VisualStudio
- 右键单击您的项目
- 选择“添加新”
- 选择WCF服务
查看Visual Studio添加的代码,并遵循该模式提供服务。最简单的方法是
- 进入VisualStudio
- 右键单击您的项目
- 选择“添加新”
- 选择WCF服务