根据下面的代码片段,我有一个 WCF Rest 服务
[ServiceContract]
public interface IService
{
[OperationContract]
[WebInvoke(UriTemplate="/SaveList/Foos/",Method="POST")]
bool SaveList(List<Foo> myFoos);
}
该服务是自托管服务,并使用 webHttpBinding 公开一个端点。我有一个客户端控制台应用程序,它具有以下代码片段:
public void Send()
{
var myObj = new Foo{Id=1, Name="Test"};
using (WebChannelFactory<OurService.Services.IOurService> cf = new WebChannelFactory<IOurService>("WebHttpBinding_IService"))
{
IUtranetService channel = cf.CreateChannel();
using (new OperationContextScope(channel as IContextChannel))
{
var status = channel.SaveList(new[] { myObj });
}
}
}
客户端代码抛出如下异常:在“http://localhost:1133/Service/SaveList”处没有监听可以接受消息的端点。
我不确定我哪里出错了。如果我从服务合同中删除 UriTemplate,客户端会返回正确的响应。
任何帮助将不胜感激。
问候鲁奇特拉