none
Service cross domain

Respuestas

Todas las respuestas

  • You need to use an endpoint with the WebHttpBinding / WebHttpBehavior, and on the binding you need to set the CrossDomainScriptAccessEnabled to true. With that you'll be able to use JSONP calls to make cross-domain GET requests to the service.

    Notice that if you want to enable x-domain calls for other HTTP verbs (e.g., POST, DELETE, PUT), you need to support the CORS (Cross-Origin Resource Sharing) protocol, and this is not supported out-of-the-box for WCF. You should be able to write an extension for that, but you can also look at the ASP.NET Web APIs, for which I've already wrote a CORS extension (part 1, part 2).


    Carlos Figueira

    lunes, 19 de marzo de 2012 15:15
    Moderador
  • Thanks for your reply.

    I set the  CrossDomainScriptAccessEnabled to true. We can get the data from WCF API in IE8 browser for the JQuery old version. But we can't get the data in other browsers. Using JSONP we received the status code 200, but the response text gives PARSERERROR. I will go through your  ASP.NET Web APIs for the further implementation.

    - Prathees kumar C

    martes, 20 de marzo de 2012 5:17
    • Marcado como respuesta Pratheeskkvi martes, 27 de marzo de 2012 13:19
    miércoles, 21 de marzo de 2012 14:25
  • Thank you for your valuable reply.

    WCF service working fine for me with ResponseFormat=WebMessageFormart.Json and with "Access-Control-Allow-Origin", "*" for cross domain issue and its working of the browsers. This URL also helpful to me http://stackoverflow.com/questions/5686059/how-to-avoid-cross-domain-policy-in-jquery-ajax-for-consuming-wcf-service.

    Prathees kumar C

    • Marcado como respuesta Pratheeskkvi martes, 27 de marzo de 2012 13:35
    martes, 27 de marzo de 2012 13:26
  • For cross domain

    [OperationContract]
    [WebGet(ResponseFormat = WebMessageFormat.Json)] // requires crossdomain settings 
    //[ScriptMethod(ResponseFormat = ResponseFormat.Json)] // no crossdomain settings required
    public string GetNumber(string id)
    {
        return "query response on id: " + id;
    }

    Along with 

    HttpContext.Current.Response.AddHeader("Access-Control-Allow-Origin", "*");
     
    if (HttpContext.Current.Request.HttpMethod == "OPTIONS")
    {
    HttpContext.Current.Response.AddHeader("Access-Control-Allow-Methods", "GET, POST");
          HttpContext.Current.Response.AddHeader("Access-Control-Allow-Headers", "Content-Type, Accept");
            HttpContext.Current.Response.AddHeader("Access-Control-Max-Age", "1728000");
            HttpContext.Current.Response.End();
    }


    -Prathees kumar C


    • Marcado como respuesta Pratheeskkvi viernes, 30 de marzo de 2012 3:49
    viernes, 30 de marzo de 2012 3:49