REST / SOAP endpoints for a WCF service

前端 未结 6 1451
囚心锁ツ
囚心锁ツ 2020-11-22 03:05

I have a WCF service and I want to expose it as both a RESTfull service and as a SOAP service. Anyone has done something like this before?

6条回答
  •  误落风尘
    2020-11-22 03:53

    This is what i did to make it work. Make sure you put
    webHttp automaticFormatSelectionEnabled="true" inside endpoint behaviour.

    [ServiceContract]
    public interface ITestService
    {
    
        [WebGet(BodyStyle = WebMessageBodyStyle.Bare, UriTemplate = "/product", ResponseFormat = WebMessageFormat.Json)]
        string GetData();
    }
    
    public class TestService : ITestService
    {
        public string GetJsonData()
        {
            return "I am good...";
        }
    }
    

    Inside service model

       
    
        
        
        
        
          
            
          
        
      
    

    EndPoint Behaviour

      
        
          
          
        
      
    

提交回复
热议问题