The remote server returned an error: (405) Method Not Allowed. WCF REST Service

前端 未结 6 840
攒了一身酷
攒了一身酷 2021-01-18 02:09

This question is already asked elsewhere but those things are not the solutions for my issue.

This is my service

[WebInvoke(UriTemplate = \"\", Metho         


        
6条回答
  •  迷失自我
    2021-01-18 02:52

    After spending 2 days on this, using VS 2010 .NET 4.0, IIS 7.5 WCF and REST with JSON ResponseWrapped, I finally cracked it by reading from "When investigating further..." here https://sites.google.com/site/wcfpandu/useful-links

    The Web Service Client code generated file Reference.cs doesn't attribute the GET methods with [WebGet()], so attempts to POST them instead, hence the InvalidProtocol, 405 Method Not Allowed. Problem is though, this file is regenerated when ever you refresh the service reference, and you also need a dll reference to System.ServiceModel.Web, for the WebGet attribute.

    So I've decided to manually edit the Reference.cs file, and keep a copy. Next time I refresh it, I'll merge my WebGet()s back in.

    The way I see it, it's a bug with svcutil.exe not recognising that some of the service methods are GET and not just POST, even though the WSDL and HELP that the WCF IIS web service publishes, does understand which methods are POST and GET??? I've logged this issue with Microsoft Connect.

提交回复
热议问题