WCF and JSON binding

后端 未结 3 1522
说谎
说谎 2021-01-06 12:32

I am trying to create a wcf service that returns json. I have some problems with my config file and i also don\'t know how to test it.



        
3条回答
  •  心在旅途
    2021-01-06 12:43

    You need to add the to the list of endpoint behaviors. Also, the endpoint needs to use the webHttpBinding. And finally, to respond to GET HTTP requests, you need to use the WebGet attribute (instead of WebInvoke(Method="GET").

       
         
           
            
             
             
             
               
                 
               
             
           
         
         
           
             
               
             
           
           
             
               
               
               
               
             
           
         
       
    

    And the service contract:

    [ServiceContract]  
    public interface IContact  
    {  
        [OperationContract]  
        [WebGet(BodyStyle = WebMessageBodyStyle.Bare, ResponseFormat = WebMessageFormat.Json, UriTemplate = "contact")]  
        Contact GetContact(int idContact);        
    }  
    

提交回复
热议问题