Pregunta

I have created a WCF service which receives data from the database of mySQL and shows as JSON data in the browser.

JSON data retrurned in the browser is as follows:

{"shipmentDetails":[{"Name":"AAA","Number":"123"},{"Name":"BBB","Number":"321"}]}

But I am unable to modify this service as cross domain access enabled,

The error comes here: web.config

<webHttpBinding>

<binding name="jsonpWebHttpBinding"  'crossDomainScriptAccessEnabled="true"></binding>

</webHttpBinding>

I kindly request anyone to help me out why this attribute is not supported.

Thanks in advance.

¿Fue útil?

Solución

(Adding the answer after OP confirmed that my comments pointed him in the right direction...)

The reason why the OP got the The 'crossDomainScriptAccessEnabled' attribute is not allowed error was because this attribute was first introduced in .NET 4.0 and the OP's project was targeting .NET 3.5. After changing the project to .NET 4.0, the problem was fixed.

Otros consejos

Why do you have symbol ' before attribute crossDomainScriptAccessEnabled?

If you host your service on IIS, you can try this one:

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

It will give you more control over domain for accessing and methods for accessing.

You can also write your behavior to add proper headers to you messages: Cross-domain

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top