我有一个现有的服务,如下方法:
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
[ServiceBehavior(AddressFilterMode = AddressFilterMode.Any)]
public class SomeService : ISomething
{
public SomeListResults SomeList(SomeParams someParams)
{
....
}
}
有没有一种简单的方法可以同时允许 JSONP 调用和 JSON(检测它)。这是本土的吗?
更新您的配置,如下所示:
<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>
请参阅此处的博客文章 http://pranayamr.blogspot.com/2011/06/calling-cross-domain-wcf-service-using.html提供创建可跨域访问的 wcf 服务的演练。
这将使您的服务能够接受来自跨域源的请求。
在确定是否填充您的响应(jsonp 中的 p)方面,
感谢@carlosfigueira:
如果使用 .Net 4,则本机支持 JSONP。只要请求有一个名为“callback”的查询字符串参数(这个名称可以配置),响应就会用函数名称填充
。
否则,您需要编写一个自定义消息检查器来适当地填充响应。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)