如何使本地JSONP现有WCF服务? [英] How to natively enable JSONP for existing WCF service?
问题描述
我有一个像下面的方法现有的服务:
I have a an existing service like the below method:
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
[ServiceBehavior(AddressFilterMode = AddressFilterMode.Any)]
public class SomeService : ISomething
{
public SomeListResults SomeList(SomeParams someParams)
{
....
}
}
有没有一种简单的方法,让JSONP调用,也JSON在同一时间(检测到它)。这是原生?
Is there a simple way to allow JSONP calls and also JSON at the same time (detect it). Is this native?
推荐答案
更新你的配置看起来像:
Update your config to look like:
<configuration>
<system.web>
<compilation debug="true" targetframework="4.0">
<authentication mode="None">
</authentication></compilation></system.web>
<system.webserver>
<modules runallmanagedmodulesforallrequests="true">
</modules></system.webserver>
<system.servicemodel>
<servicehostingenvironment **aspnetcompatibilityenabled**="true">
<standardendpoints>
<webscriptendpoint>
<standardendpoint **crossdomainscriptaccessenabled**="true" name="">
</standardendpoint></webscriptendpoint>
</standardendpoints>
</servicehostingenvironment></system.servicemodel>
</configuration>
在这里看到一篇博客文章一>提供创建WCF服务,这是访问的跨域的演练。
See here for a blog post providing a walkthrough of creating a wcf service that's accessible cross-domain.
这将使你的服务接受跨域资源的请求。
This will enable your service to accept requests from cross-domain sources.
在确定条款是否垫你的回应(在JSONP的P)
In terms of determining whether to pad your response (the p in jsonp),
由于@carlosfigueira此:
Thanks to @carlosfigueira for this:
如果使用.NET 4中JSONP是原生支持。只要请求有所谓的回调(这个名字可配置)查询字符串参数,响应将与函数名称进行填充
。
If using .Net 4 JSONP is supported natively. As long as the request has a query string parameter called "callback" (this name can be configured), the response will be padded with the function name .
否则,你需要编写适当垫响应的自定义消息检查。
Otherwise, you'll need to write a custom message inspector that pads the response appropriately.
这篇关于如何使本地JSONP现有WCF服务?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!