When trying to add a CORS setting by enabling the "Access-Control-Allow-Origin" header in the Web Service method shown below. However, I'm still getting the error: No 'Access-Control-Allow-Origin' header is present on the requested resource.' Though found some solutions online, by which I can't get the solution. Please suggest.
The Development Language is C#/ .NET
Loading
Md Tahmidul AbedinPosted Nov 1, 2023, 9:32 AM
In the Web.config file of this web service, you have to add the following XML:
In the time of adding the above XML, we have to be careful to add this after tag. I faced the same issue recently and searching for the solution for a long time. Hope it will solve your issue. :)
Prasad RaveendranPosted Oct 28, 2023, 12:58 AM
Enabling Cross-Origin Resource Sharing (CORS) for a SOAP web service in Visual Studio can be a bit different from enabling it for RESTful services because SOAP services typically use WCF (Windows Communication Foundation) in the .NET environment.
To enable CORS for a SOAP web service in Visual Studio, you might need to modify the configuration of your WCF service to include the necessary HTTP headers for CORS. Below are the general steps you can follow:
Here's an example of how you might create a custom message inspector to add CORS headers:
2. Configure the Service with Custom Behavior: Add your custom behavior to the service configuration in your web.config file.
Inside your web.config file, add the following:
Ensure you replace "YourNamespace" and "YourService" with the appropriate namespaces and service names in your project.
3. Testing: After making these changes, test your SOAP service to ensure that the 'Access-Control-Allow-Origin' header is being added to the responses.
Remember, the 'Access-Control-Allow-Origin' header is set to "*" in the provided code, allowing requests from any origin. You might want to restrict this based on your security requirements.
Keep in mind that these steps are an example and might need adjustments based on your specific WCF service setup in Visual Studio. Always test thoroughly and adapt as needed.