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>