English 中文(简体)
我怎么能为世界妇联的Ria服务添加“JSONP”终端,以便能够发出交叉电话?
原标题:how can I add a JSONP endpoing for WCF Ria Services to enable cross-domain calls?

I m aware that WCF RIA Services has a Microsoft.ServiceModel.DomainServices.Hosting.JsonEndpointFactory that I can use to enable JSON. I need to enable cross-domain calls via JSONP. Is there an existing DomainServiceEndpointFactory that will accomplish this?

最佳回答

我只需要这样做——我放弃了JsonEndpointFactory,并随同在那里具有约束力的那样,然后用新类别增加了一个终点。

namespace Bodge
{
    public class JsonPEndpointFactory : JsonEndpointFactory
    {
        public override IEnumerable<ServiceEndpoint> CreateEndpoints(DomainServiceDescription description, DomainServiceHost serviceHost)
        {
            IEnumerable<ServiceEndpoint> endPoints = base.CreateEndpoints(description, serviceHost);
            foreach (ServiceEndpoint endPoint in endPoints)
            {
                if (endPoint.Binding is WebHttpBinding)
                {
                    ((WebHttpBinding)endPoint.Binding).CrossDomainScriptAccessEnabled = true;
                }
            }

            return endPoints;
        }
    }
}

  <endpoints>
    <add name="JSONP" type="Bodge.JsonPEndpointFactory, Bodge, Version=1.0.0.0"/>
  </endpoints>

Then access your service with the endpoint and the callback query param e.g. http://blah/service.svc/JSONP/GetStuff?callback=callbackname

Hope that helps, Chris.

问题回答

评论的形式很少,因此,今后在此参考的是必要的使用和集会。

非常感谢,这是我所需要的。 供今后参考的是:

Namespaces:

using System.Web;
using System.ServiceModel;
using System.ServiceModel.Description;
using System.ServiceModel.DomainServices.Hosting;
using System.ServiceModel.DomainServices.Server;
using Microsoft.ServiceModel.DomainServices.Hosting;

Assemblies

NET 4.0

System.ServiceModel
System.ServiceModel.Web

WCF RIA Services V1.0 SP2 RC

System.ServiceModel.DomainServices.Hosting
System.ServiceModel.DomainServices.Server

WCF RIA Services Toolkit (September 2011)

Microsoft.ServiceModel.DomainServices.Hosting




相关问题
is JsonP working with Opera, Chrome & Safari?

On a web site that I am building , when you log in (because the database is on an other server), I use json padding to check if the user as the right credentials. It s working flawlessly (ie7,ie8 &...

Why same origin policy for XMLHttpRequest

Why do browsers apply the same origin policy to XMLHttpRequest? It s really inconvenient for developers, but it appears it does little in actually stopping hackers. There are workarounds, they can ...

XML cannot be the whole program

I am using jquery to make an $.ajax() call to a REST web service. Based on the documentation I found, I need to use jsonp as the datatype in order to make this cross domain call (an XML document is ...

Drupal node.save and JSONP

I am having an issue with call Drupal node.save using MooTool s JSONP. Here is an example. Here is my request: callback Request.JSONP.request_map.request_1 method node.save sessid 123123123123123 ...

JSONP + onbeforeunload + back button + problems

I am trying to make a JSONP call to a server on the beforeunload event. This all works great until I start playing with the back button. If I navagate away from the page and then press back next ...

Error handling in getJSON calls

How can you handle errors in a getJSON call? Im trying to reference a cross-domain script service using jsonp, how do you register an error method?

热门标签