convert a WCF Service, to a RESTful application?

前端 未结 4 2073
北荒
北荒 2021-01-02 04:45

Hey im not getting anywhere with turning wcf into a restful service. So I was wondering if some one can take the basic code when you start a WCF Service application here:

4条回答
  •  旧巷少年郎
    2021-01-02 05:10

    When configuring a simple WCF REST service, in the past I've had an error similar to what your having. In the article mentioned by Justin:
    A Guide to Designing and Building RESTful Web Services with WCF 3.5
    (search for - Defining the HTTP Interface: [WebGet])

    You'll notice that the Get methods all take strings.

    The error you have is common when you try and convert one of the sample WCF projects to a RESTful one. To fix, simply change the signature of the method and the interface to accept a string, as opposed to an int, this is what inner exception is complaining about:

    Operation 'GetData' in contract 'IService1' has a path variable named 'value' which does not have type 'string'. Variables for UriTemplate path segments must have type 'string'

    original:

    public string GetData(int value)
    

    modified:

    public string GetData(string value)
    

    Here's a simple .config section from a sample project I have, that I know works:

    
        
          
            
              
            
          
        
        
          
            
          
        
      
    

提交回复
热议问题