[英]Where should I look: WCF Rest - POST Endpoint Not Found
我已經研究了近兩天,這表明它將是一個非常簡單的解決方案:
我有WCF REST服務。 GET非常適合返回JSON,但是在POST中,我只會收到Chrome和Fiddler中找不到的Endpoint。
我將提供GET和POST屬性,以防萬一我通過GET方法破壞了它。
<services>
<service name="WCFServiceWebRole1.Class" behaviorConfiguration="serviceBehavior">
<endpoint address=""
binding="webHttpBinding"
contract="WCFServiceWebRole1.IClass"
behaviorConfiguration="web">
</endpoint>
</service>
<service name="WCFServiceWebRole1.ClassPost" behaviorConfiguration="serviceBehavior">
<endpoint address=""
binding="wsHttpBinding"
contract="WCFServiceWebRole1.IClassPost"
behaviorConfiguration="web">
</endpoint>
</service>
</services>
一件事對我來說很突出,那不是為GET設置的。 通過更改它,我破壞了解決方案的GET,但是通過從POST中刪除它並不會改變這種情況。
我的服務合同如下所示:
[ServiceContract]
public interface IClass
{
[WebInvoke(ResponseFormat = WebMessageFormat.Json,
BodyStyle = WebMessageBodyStyle.Bare,
UriTemplate = "/GET/?json={jsonString}", Method = "GET")]
string Decode(string jsonString);
// TODO: Add your service operations here
}
[ServiceContract]
public interface IClassPost
{
[WebInvoke(ResponseFormat = WebMessageFormat.Json,
BodyStyle = WebMessageBodyStyle.Bare,
UriTemplate = "/POST/?json={jsonString}", Method = "POST")]
string DecodePost(string jsonString);
}
最后,我在同一文件中有兩個相同的類:
public class ClassPost : IClassPost
{
public string DecodePost(string queryString)
{
string Deserialized = JsonCleaner.CleanAllWhiteSpace(JsonConvert.DeserializeObject(queryString).ToString());
return Deserialized;
}
GET上Decode的類是相同的,方法和類相同。
如何獲得有關失敗原因的更多信息,或者我做錯了什么? (到目前為止,Stack Overflow上的所有問題都不存在,否則似乎沒有相同的問題/解決方案)。
原來是我的服務合同有問題。
將其更改為單獨的ServiceContracts。
將所有OperationContracts移到一個服務合同中可以解決此問題,因此看起來像這樣:
[ServiceContract]
public interface IClass
{
[WebInvoke(ResponseFormat = WebMessageFormat.Json,
BodyStyle = WebMessageBodyStyle.Bare,
UriTemplate = "/GET/?json={jsonString}", Method = "GET")]
string Decode(string jsonString);
[WebInvoke(ResponseFormat = WebMessageFormat.Json,
BodyStyle = WebMessageBodyStyle.Bare,
UriTemplate = "/POST/?json={jsonString}", Method = "POST")]
string DecodePost(string jsonString);
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.