0

根据下面的代码片段,我有一个 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,客户端会返回正确的响应。

任何帮助将不胜感激。

问候鲁奇特拉

4

1 回答 1

1

您的 URI 模板不正确。您需要将其更改为:

 [WebInvoke(UriTemplate="/SaveList/Foos/SaveList",Method="POST")] 

它不会自动附加您的方法名称。

另外根据我留下的评论仅供参考,您不需要 Method="Post"

于 2012-08-09T10:32:03.900 回答