Add WebAPI Project or use webHttpBinding?
I would like to get the communities thoughts on what would be the best practice (or pros and cons) for the following scenario:
We have an existing WCF service, which is exposed via the default basicHttpBinding
We now have a requirement to access the service from a JavaScript client via AJAX - however, this client is running on a different application and hence a different domain.
Therefore, Cross-Origin Resource Sharing (CORS) needs to be allowed.
I am trying to decide if it is best to:
1) Expose another WCF endpoint using the webHttpBinding AND alter the WCF service to add the appropriate CORS headers to allow the AJAX request to come from the JavaScript client's domain See this article: https://www.codeproject.com/Articles/845474/Enabling-CORS-in-WCF
Or
2) Add another project to the WCF solution, a WebAPI project and then just have the WCF project and WebAPI projects as thin service wrappers to the underlying service logic.
The Pros and Cons I see:
Option 1 Pros: - doesn't require adding a new project to the solution - we can maintain a single service contract for the WCF service
Option 1 Cons: - we have to add a Global.asax file and add the CORS headers to the response in addition to enabling the handling of OPTIONS requests - WCF isn't as well geared to supporting RESTful features eg content negoiation (although this isn't a current requirement)
Option 2 Pros: - WebAPI is better geared to support CORS (we dont have to write specific code to add the headers we can do it through attributes on the controller methods)
Option 2 Cons: - we will need to have two service interfaces, one for WCF and one for WebAPI, which opens the possibility of these becoming out of sync - a maintenance concern
Are there any other concerns? Or is my understanding on the two options misguided at all?
What do people think is the best practice solution?
链接地址: http://www.djcxy.com/p/20410.html