Search code examples
c#jsonwcfrestwcf-endpoint

Where should I look: WCF Rest - POST Endpoint Not Found


I have been digging through this for nearly two days, which suggests its going to be a very simple fix:

I have a WCF REST service. GET works great for returning a JSON, however in POST I only receive Endpoint not found in Chrome, as well as in Fiddler.

I will provide the GET and POST properties in case I did something to break it through the GET methods.

<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>

One thing stands out to me, and that's that is not set for GET. By changing it, I break GET for the solution, however by removing it from POST it does not change the situation.

My service contract then looks like so:

[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);
}

Then finally, I have two identical classes in the same file:

public class ClassPost : IClassPost
    {
        public string DecodePost(string queryString)
        {
            string Deserialized = JsonCleaner.CleanAllWhiteSpace(JsonConvert.DeserializeObject(queryString).ToString());
            return Deserialized;
        }

The class for Decode on GET is identical, identical method and class.

How can I either get more info on why this is failing, or what did I do wrong? (And so far none of the issue on Stack Overflow or otherwise seem to have the same issue/ resolution).


Solution

  • This turned out to be a problem with my service contract.

    Changing it to seperate ServiceContracts.

    Moving all OperationContracts inside one service contract corrected the issue, so it looks like so:

    [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);
    }