0

I am using ria services with jsonp endpoint. When I call my method in service file it works fine in ie and firefox but sometimes works in chrome and sometimes I get "Cross domain javascript callback is not supported in authenticated services." error. Even I dont use authenticated services.

Here is a piece of code about what I have.

Jsonp service

    [EnableClientAccess(RequiresSecureEndpoint = false)]
    public class PPolJsonService : LinqToEntitiesDomainService<PPolAdvEntities>
    {

       public IQueryable<QuestionEntity> GetCompleteSurvey()
       {
        ............
       }
    }

javascript code

 function (data) {
                        var Params = {};
                        Params.type = 'GET';
                        Params.url = 'http://127.0.0.1:81/PPolSilverlight-Web-Services-PPolJsonService.svc/JSONP/GetCompleteSurvey;
                        Params.dataType = 'jsonp';

                        Params.data = { data:'somedata'};
                        Params.success = function (data) { };
                        Params.jsonpCallback = "ppolv2"
                        $.ajax(Params);
                    });

In web.config file my setting is <authentication mode="Forms">

İf I set <authentication mode="None"> I am be able to solve all problems with chrome. But the rest of the application needs authentication. So thats why I have to use it as "mode=Forms". And as you see my service does not use authentication so,

Why I am getting this error and is there any solution for it?

Note:

By the way I have other settings in web.config like

  <webHttpEndpoint>
        <standardEndpoint crossDomainScriptAccessEnabled="true"
                          automaticFormatSelectionEnabled="true"/>
      </webHttpEndpoint>

or these in clientaccesspolicy.xml

<?xml version="1.0" encoding="utf-8"?>
<access-policy>
  <cross-domain-access>
    <policy>
      <allow-from http-request-headers="*">
        <domain uri="http://*"/>
        <domain uri="https://*" />
      </allow-from>
      <grant-to>
        <resource path="/" include-subpaths="true"/>
      </grant-to>
    </policy>
  </cross-domain-access>
</access-policy>

but none of them is helping me.

Thanks in advance.

serhads
  • 462
  • 2
  • 7
  • 22

2 Answers2

1

Hi Try to add this line to your web.config files. It enables Cross-domain Ajax Requests.

<?xml version="1.0" encoding="utf-8"?>
<configuration>
 <system.webServer>
   <httpProtocol>
     <customHeaders>
       <add name="Access-Control-Allow-Origin" value="*" />
     </customHeaders>
   </httpProtocol>
 </system.webServer>
</configuration>
Marian Ban
  • 8,158
  • 1
  • 32
  • 45
  • Do you have service and web published on same iis site? if yes then try to use relative path in Params.url. – Marian Ban Jun 13 '12 at 11:55
  • Unfortunately This javascript need to be call from any webpage. So they are not on same iis site. – serhads Jun 13 '12 at 12:14
0

I haven't test it enough but I guess I found a solution.

İf you use secure endpoint in your application and if you don't need to use secure endpoint for jsonp services,

you can add requireSSL="true" in

 <authentication mode="Forms">
  <forms name=".PPolSilverlight_ASPXAUTH" timeout="2880" requireSSL="true" />
</authentication>

with this small piece of code your unsecure jsonp services will be able to work without authentication.

serhads
  • 462
  • 2
  • 7
  • 22