您的位置:首页 > 其它

WCF 改成 restful api

2016-05-22 19:19 429 查看
1. 右健 svc , view markup, 添加

Factory="System.ServiceModel.Activation.WebServiceHostFactory"

2. 在接口上添加:

[WebInvoke(UriTemplate = "{name}/{type}/{count}", Method = "GET", ResponseFormat = WebMessageFormat.Json)]

3. No 'Access-Control-Allow-Origin' header is present on the requested resource

3.1 add the CORS NuGet package. In Visual Studio, from the Tools menu, select Library Package Manager, then select Package Manager Console. In the Package Manager Console window, type the following command:

Install-Package Microsoft.AspNet.WebApi.Cors 

3.2 类上加,不是接口上加

[EnableCors(origins: "http://www.48.red:81", headers: "*", methods: "*")]


3.3 web.config:

<system.webServer>
...

<httpProtocol>
<customHeaders>
<!-- Enable Cross Domain AJAX calls -->
<remove name="Access-Control-Allow-Origin" />
<add name="Access-Control-Allow-Origin" value="*" />
</customHeaders>
</httpProtocol>
</system.webServer>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: