代码之家  ›  专栏  ›  技术社区  ›  Gans

具有多操作合约的WCF Rest服务

  •  0
  • Gans  · 技术社区  · 6 年前

    我想用这样的操作契约创建WCF Rest服务

    public interface ICustomerService  
    {  
        [OperationContract]
        [WebInvoke(Method = "GET", RequestFormat = WebMessageFormat.Json,  
                ResponseFormat = WebMessageFormat.Json, UriTemplate = "/GetAllCustomer/")]  
        List<CustomerDataContract> GetAllCustomer();  
    
        [OperationContract]
        [WebInvoke(Method = "GET", RequestFormat = WebMessageFormat.Json,  
                ResponseFormat = WebMessageFormat.Json, UriTemplate = "/GetSTOCK/ABC")]  
        List<CustomerDataContract> GetSTOCK();  
    
        [OperationContract]
        [WebInvoke(Method = "GET", RequestFormat = WebMessageFormat.Json,  
                ResponseFormat = WebMessageFormat.Json, UriTemplate = "/GETSUPINFO/XYZ/ABC")]  
        List<CustomerDataContract> GETSUPINFO();   
    } 
    

    有人能帮忙吗?

    1 回复  |  直到 6 年前
        1
  •  0
  •   Lawrence Lu    6 年前

    有两种方法可以让Restful服务协议支持您的逻辑。第一个是更改WCF服务,您可以参考以下链接了解更多详细信息。 https://msdn.microsoft.com/en-us/library/dd203052.aspx

    https://msdn.microsoft.com/en-us/library/bb412178(v=vs.90).aspx

    更简单的方法是用WepAPI封装您的逻辑,只需保持WCF服务不变。您还可以从以下关于WebAPI的链接获得更多信息。

    https://msdn.microsoft.com/en-us/library/hh833994(v=vs.108).aspx