tags:

views:

31

answers:

2

I have a simple WCF contract that contains both 'GET' and 'POST' operations. I have the service running on localhost. I am able to type the service address into my browser and see the service response values. When I try to do the same thing from C# code, I get the error "There was no endpoint listening at...." message. I can however call a 'POST' method on the service from in code.

What am I missing? Below is my Contract code

using System;
using System.ServiceModel;
using System.ServiceModel.Web;

namespace WebServiceTest.Services
{
    [ServiceContract]
    public interface ITestOne
    {
        [OperationContract]
        [WebInvoke(
            Method = "GET", 
            ResponseFormat = WebMessageFormat.Json,
            BodyStyle = WebMessageBodyStyle.Wrapped,
            UriTemplate = "GetGreeting/{text1}/{text2}")]
        string HelloWorld(string text1, string text2);

        [OperationContract]
        [WebInvoke(
            Method = "GET",
            ResponseFormat = WebMessageFormat.Json,
            BodyStyle = WebMessageBodyStyle.Wrapped,
            UriTemplate = "Greet/{text1}")]
        string HelloWorld2(string text1);

        [OperationContract]
        [WebInvoke(
            Method="GET",
            ResponseFormat = WebMessageFormat.Json,
            BodyStyle = WebMessageBodyStyle.Wrapped,
            UriTemplate = "Add/{value1}/{value2}")]
        int Add(string value1, string value2);

        [OperationContract]
        [WebInvoke(Method = "POST",
                    ResponseFormat = WebMessageFormat.Json,
                    BodyStyle = WebMessageBodyStyle.Wrapped)]
        String GetAllSpecies();

        [OperationContract]
        [WebInvoke(
            Method = "GET",
            ResponseFormat = WebMessageFormat.Json,
            BodyStyle = WebMessageBodyStyle.Wrapped,
            UriTemplate = "specie")]
        String GetAllSpecies2();

}

}

A: 

Does it work without the Template?

KevinDeus
No, I can now say that the problem is that the client code is issuing a 'POST' request and not a 'GET'. But I don't know why. I am using a WebChannelFactory which I thought would default to a webHttpBinding.
John
+1  A: 

I found the answer. The problem was that the service was using the service contract ITestOne and the client was using the generated proxy client for ITestOne (obtained through MEX endpoint). The generated proxy did not contain the [WebGet] attribute that the service contract contained.

John