Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using CORS + SOAP + WCF for a HTTPS service

I'm trying to get CORS working for a new version of our SOAP web service (which runs under HTTPS and has username/password authentication) which can be connected to via JS.

At the moment I'm getting it working fine locally (not cross-domain) but soon as it is using a different domain I get the following from the WCF Traceviewer. (400 Bad Request in IIS7)

<ExceptionString>System.Xml.XmlException: The body of the message cannot be read because it is empty.</ExceptionString>

It seems it's not even getting to the part where my message inspector runs to add the appropriate CORS headers.

Has anyone experienced this before or managed to get CORS to work under a HTTPS SOAP service?

I'd appreciate any advice you can give.

Cheers, Jamie

like image 889
Jamie Avatar asked Jul 23 '13 22:07

Jamie


1 Answers

Actually you can do this only implement the response custom header per request like this.

Response.AppendHeader("Access-Control-Allow-Origin", "*");

There are more ways to do this. You can only chooise is. Do you look the enabling cross domain access on wcf articles? Implemented a project used wcf service from wcf and wcf service hosts on cross domain. You can use jsonp with webhttp binding. example answer is here;

Cross Domain jQuery Ajax Request & WCF REST Service

or you can implement configuration like this:

<system.webServer>
 <httpProtocol>
  <customHeaders>
   <add name="Access-Control-Allow-Origin" value="*" />
  </customHeaders>
 </httpProtocol>
</system.webServer>

For best way to implement/enabling cors please check the enable-cors.org site. i can found easyly that link.

http://enable-cors.org/server_wcf.html

At least you can use jsonp instead of json. its free you but difficult to handle.

I wonder what you chooise it.

like image 53
Omer Faruk Zorlu Avatar answered Sep 17 '22 19:09

Omer Faruk Zorlu