我声明了一个WCF RESTFul服务:
[ServiceContract] public interface IGasPriceService { [OperationContract] [WebGet (ResponseFormat = WebMessageFormat.Xml, BodyStyle = WebMessageBodyStyle.Bare, UriTemplate = "/GetGasPrice/For/ZipCode/{zipCode}" )] GasPriceData GetPriceData(string zipCode); [OperationContract] [WebGet (RequestFormat = WebMessageFormat.Xml, ResponseFormat = WebMessageFormat.Xml, BodyStyle = WebMessageBodyStyle.Bare, UriTemplate = "/GetGasPrice/For/City/{city}" )] GasPriceData GetPriceDataForCity(string city); [OperationContract] [WebInvoke (Method = "POST", RequestFormat = WebMessageFormat.Xml, UriTemplate = "/SetGasPrice/For/ZipCode/{zipCode}/Price/{price}" )] void SetPriceDataForZipCode(string zipCode, string price); }
方法GetPriceData和GetPriceDataforCity工作,但SetPriceDataForZipCode不起作用.任何人都可以让我知道为什么这种无法发挥作用.
当我发出如下请求时:
HTTP://本地主机:7002/SetGasPrice /为/邮编/ 45678/7.80
我收到的消息是:
EndPoint Not Found
任何想法如何解决这一问题?
我改成了
HTTP://本地主机:7002/SetGasPrice /为/邮编/ 54568/5.788
和
[OperationContract] [WebInvoke (Method = "POST", RequestFormat = WebMessageFormat.Xml, UriTemplate = "/SetGasPrice/For/ZipCode/{zipCode}/{price}" )] void SetPriceDataForZipCode(string zipCode, string price);
这给了我一个信息:
方法不允许.
任何想法如何解决这个问题?
你的网址需要是:
http://localhost:7002/SetGasPrice/For/ZipCode/45678/Price/7.80
或者您需要将模板更改为:
"/SetGasPrice/For/ZipCode/{zipCode}/{price}"