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 类上加,不是接口上加
3.3 web.config:
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>
相关文章推荐
- 本周学习进度
- ArcGIS Engine开发中利用GP工具时常出现的错误
- bzoj3143【HNOI2013】游走
- 运算符重载加法(单目)
- 单链表排序(冒泡排序法)
- EXPORT_SYMBOL
- ArcGIS Engine开发中利用GP工具时常出现的错误
- JSP9大内置对象及方法
- Android开发之Fragment的生命周期
- mysql基本操作
- spring整合技术之---利用JDBC访问数据库
- 运算符重载加法(双目)
- Nginx日志分割脚本
- Ruby中的变量定义
- NetBeans8.1开发Spring MVC的基础代码
- poj 3070 Fibonacci(矩阵加速DP)
- Leetcode--Flatten Binary Tree to Linked List
- shader内置函数
- 学习进度条
- JavaScript 基础(七) 箭头函数 generator Date JSON