gpt4 book ai didi

WCF Restful 帖子

转载 作者:行者123 更新时间:2023-12-01 16:00:41 29 4
gpt4 key购买 nike

我有一个 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);

这给了我这样的信息:

方法不允许。

有什么想法可以解决这个问题吗?

最佳答案

您的网址必须是:

 http://localhost:7002/SetGasPrice/For/ZipCode/45678/Price/7.80

或者您需要将模板更改为:

"/SetGasPrice/For/ZipCode/{zipCode}/{price}"

关于WCF Restful 帖子,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/385451/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com