JsonConvert.DeserializeObject and “d” wrapper in WCF

后端 未结 7 499
梦谈多话
梦谈多话 2020-12-21 08:53

By default WCF service wrap JSON response in \"d\" wrapper and there I found a problem with parsing it.

If I parse with JsonConvert.DeserializeObject(respons

7条回答
  •  执念已碎
    2020-12-21 09:18

    Maybe this helps.

    The service:

    namespace Application.Service
    {
            [ServiceBehavior(UseSynchronizationContext = false,
            ConcurrencyMode = ConcurrencyMode.Multiple,
            InstanceContextMode = InstanceContextMode.PerCall),
            AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
            public class VendorService : IVendorService
            {
              public List RetrieveMultiple(int start, int limit, string sort, string dir)
              {
                 //I don't do any manual serialization
                 return new Vendor();
              }
            }
    }
    

    The contract:

        [ServiceContract(Namespace = "Application.Service.Contracts")]            
        public interface IVendorService
        {
           [OperationContract]
           [WebInvoke(ResponseFormat=WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.WrappedRequest)]
            List RetrieveMultiple(int start, int limit, string sort, string dir);
         }
    

    My Svc file has just this line:

    <%@ ServiceHost Service="Application.Service.VendorService" %>
    

    Web.config

    
        
        
          
            
              
              
            
          
          
            
              
              
            
            
              
              
            
          
        
    
      
        
      
    

提交回复
热议问题