REST / SOAP endpoints for a WCF service

前端 未结 6 1442
囚心锁ツ
囚心锁ツ 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:43

    We must define the behavior configuration to REST endpoint

    
      
       
      
    
    

    and also to a service

    
       
         
          
       
    
    

    After the behaviors, next step is the bindings. For example basicHttpBinding to SOAP endpoint and webHttpBinding to REST.

    
       
         
       
       
         
       
    
    

    Finally we must define the 2 endpoint in the service definition. Attention for the address="" of endpoint, where to REST service is not necessary nothing.

    
      
        
        
        
      
    
    

    In Interface of the service we define the operation with its attributes.

    namespace ComposerWcf.Interface
    {
        [ServiceContract]
        public interface IComposerService
        {
            [OperationContract]
            [WebInvoke(Method = "GET", UriTemplate = "/autenticationInfo/{app_id}/{access_token}", ResponseFormat = WebMessageFormat.Json,
                RequestFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.Wrapped)]
            Task autenticationInfo(string app_id, string access_token);
        }
    }
    

    Joining all parties, this will be our WCF system.serviceModel definition.

    
    
      
        
          
            
          
        
        
          
            
            
          
        
      
    
      
        
          
        
        
          
        
      
    
      
        
      
    
      
    
      
        
          
          
          
        
      
    
    
    

    To test the both endpoint, we can use WCFClient to SOAP and PostMan to REST.

提交回复
热议问题