2010年9月6日 星期一

WCF 3.5/4.0 REST 設定(WCF REST Service Template)

1.在你的 SVC 檔案加上 Factory="System.ServiceModel.Activation.WebServiceHostFactory"
2.修改 Web.config 將 這個 node 內跟這個 Service 有關的全部刪除
3.如果安裝在IIS 6 還要做以下的動作(做完要IIS_RESET 才會生效)
On IIS configuration of extensions mappings, edit the .svc mapping and remove the "Check that file exists" checkbox. that should do the magic. If you get Authentication errors, make sure the IIS site is not configured to allow windows integrated security, only anonymous access.
4.如果你用的是 WCF REST Service Template 開發出來的專案,因為沒有 .SVC 檔,如果HOST在IIS 6,還需要額外設定  Installing Wildcard Application Mappings (IIS 6.0)
http://www.microsoft.com/technet/prodtechnol/WindowsServer2003/Library/IIS/5c5ae5e0-f4f9-44b0-a743-f4c3a5ff68ec.mspx?mfr=true

http://peterkellner.net/2008/08/24/urlrewrite-with-aspnet-urlrewriter-wildcard-mapping-iis6-iis7/
5.如果 遇到 The current identity (NT AUTHORITY\NETWORK SERVICE) does not have write access 的錯誤可以重新註冊 ASP.NET ex: aspnet_regiis -ir

如此就可以用 REST 的方式來存取 Web Service

請參考
http://beyondrelational.com/blogs/dhananjaykumar/archive/2010/08/11/webservicehost-hosting-a-wcf-rest-service.aspx


http://dhananjaykumar.net/2010/04/27/picture-gallery-for-windows-7-phone-using-wcf-rest-service/