2015-06-04 20 views
0

我已经通过这个挖近两天,这表明它的将是一个非常简单的解决办法:我应该到什么地方:WCF休息 - POST端点未找到

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

上得到解码类是相同的,相同的方法和班级。

我怎么能得到更多的信息,为什么这是失败的,或者我做错了什么? (到目前为止,堆栈溢出或其他问题似乎都没有相同的问题/解决方案)。

回答

0

原来这是我的服务合同的问题。

将其更改为单独的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); 
} 
相关问题