How to natively enable JSONP for existing WCF service?

前端 未结 2 351
天命终不由人
天命终不由人 2020-11-30 11:37

I have a an existing service like the below method:

[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
[Servic         


        
2条回答
  •  爱一瞬间的悲伤
    2020-11-30 12:27

    Update your config to look like:

    
      
        
        
      
      
        
      
      
        
        
          
            
          
        
      
    
    

    See here for a blog post providing a walkthrough of creating a wcf service that's accessible cross-domain.

    This will enable your service to accept requests from cross-domain sources.

    In terms of determining whether to pad your response (the p in jsonp),

    Thanks to @carlosfigueira for this:

    If using .Net 4 JSONP is supported natively. As long as the request has a query string parameter called "callback" (this name can be configured), the response will be padded with the function name .

    Otherwise, you'll need to write a custom message inspector that pads the response appropriately.

提交回复
热议问题