我声明了一个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://localhost:7002/SetGasPrice/For/ZipCode/45678/7.80
我得到的信息是:
EndPoint Not Found
任何想法如何解决这个问题?
我把它改成了
http://localhost:7002/SetGasPrice/For/ZipCode/54568/5.788
和
[OperationContract]
[WebInvoke
(Method = "POST",
RequestFormat = WebMessageFormat.Xml,
UriTemplate = "/SetGasPrice/For/ZipCode/{zipCode}/{price}"
)]
void SetPriceDataForZipCode(string zipCode, string price);
这给了我信息:
不允许使用方法。
有任何想法如何解决这个问题?
答案 0 :(得分:5)
您的网址必须是:
http://localhost:7002/SetGasPrice/For/ZipCode/45678/Price/7.80
或者您需要将模板更改为:
"/SetGasPrice/For/ZipCode/{zipCode}/{price}"
答案 1 :(得分:1)
试
UriTemplate = "/SetGasPrice/For/ZipCode/{zipCode}/{dollars}.{cents}"