是否可以将数据发布到JsonP?或者所有数据都必须作为GET请求在查询字符串中传递?
我有很多需要发送到服务的数据,跨域,并且它太大而无法通过查询字符串发送
有什么方法可以解决这个问题?
坚持这个问题.我有一个包含2个项目的解决方案,其中一个是带有jquery ajax调用的普通旧html,而另一个是WCF服务.html页面将发出对WCF服务的ajax调用以获取json字符串并将其用于显示目的.
现在问题是每当我在调试模式下运行时,html页面和WCF都将以不同的端口启动.当我执行测试时(即在Firefox中调用类型= OPTIONS获得405 Method Not Allowed错误),这为我创建了一个跨源问题.我会在我的ajax脚本上检查调用方法,并且WCF服务是相同的(GET).
我搜索谷歌但发现要么我必须安装扩展程序或在IIS上执行一些配置,我发现这很麻烦,因为我正在做的事情很简单.下面是一个例子,我将在web.config中添加以下配置,但它不起作用:
<system.serviceModel>
<bindings>
<webHttpBinding>
<binding name="crossDomain" crossDomainScriptAccessEnabled="true" />
</webHttpBinding>
</bindings>
<behaviors>
<endpointBehaviors>
<behavior name="MobileService.webHttpBehavior">
<webHttp />
</behavior>
</endpointBehaviors>
<serviceBehaviors>
<behavior name="MyServiceBehavior">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true"/>
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
<services>
<service name="MobileService.SimpleMemberInfo" behaviorConfiguration="MyServiceBehavior">
<endpoint address="" binding="webHttpBinding" contract="MobileService.IMemberInfo" bindingConfiguration="crossDomain" behaviorConfiguration="MobileService.webHttpBehavior">
</endpoint>
</service>
</services>
</system.serviceModel>
<system.webServer>
<httpProtocol>
<customHeaders>
<add name="Access-Control-Allow-Origin" value="*" />
<add name="Access-Control-Allow-Methods" value="GET" />
<add name="Access-Control-Allow-Headers" value="Content-Type, Accept" />
</customHeaders>
</httpProtocol>
<modules runAllManagedModulesForAllRequests="true"/>
<directoryBrowse enabled="true"/>
</system.webServer>
Run Code Online (Sandbox Code Playgroud)
任何人都有任何想法摆脱这个恼人的问题?
编辑:只是添加,我正在使用与VS …