WCF休息自动添加URITemplate

时间:2012-05-21 13:59:51

标签: wcf-rest

我有一个WCF REST服务,其中包含以下URL: HTTP:/本地主机/ GetAllOrders

但是工厂渠道总是将Uri生成为http:/localhost/Service.svc/GetAllOrders/GetAllOrders

这是我的客户工厂渠道:

Uri address = new Uri("http:/localhost/Service.svc/GetAllOrders");
            var factory = new  System.ServiceModel.Web.WebChannelFactory<App.WebService.IOrderSvc>(address);
            var webHttpBinding = factory.Endpoint.Binding as System.ServiceModel.WebHttpBinding;
            App.WebService.IOrderSvc service = factory.CreateChannel();
            var orders = service.GetAll(); // this one throwing an error since the URI has become http:/localhost/Service.svc/GetAllOrders/GetAllOrders

这是服务合同:

[WebGet(UriTemplate = "GetAllOrders")]
        [OperationContract]
        List<Order> GetAll();

任何想法为什么Uritemplate被添加两次?

1 个答案:

答案 0 :(得分:0)

Uri错了 - 它应该是服务的Uri。你应该写:

  

Uri地址=新的Uri(“http:/localhost/Service.svc /”);