G Gr
G Gr

Reputation: 6080

Service endpoint not found?

Seem to run into a service endpoint not found problem when trying to get from my service.

if I try http://localhost:8000/hello/help I should expect to see <string>You entered help <string> but I only get the no endpoint instead? I havent touched my config files at all and I am just hosting from a console app.

Host:

namespace Host
{
    class Program
    {
        static void Main(string[] args)
        {
            WebHttpBinding binding = new WebHttpBinding();
            WebServiceHost host =
            new WebServiceHost(typeof(Service1));
            host.AddServiceEndpoint(typeof(IService1),
            binding,
            "http://localhost:8000/hello");
            host.Open();
            Console.WriteLine("Hello world service");
            Console.WriteLine("Press <RETURN> to end service");
            Console.ReadLine();
        }
    }
}

Service1:

namespace WcfServiceLibrary1
{
    // NOTE: You can use the "Rename" command on the "Refactor" menu to change the class name "Service1" in both code and config file together.
    public class Service1 : IService1
    {
        public string GetData(string value)
        {
            return string.Format("You entered: {0}", value);
        }

IService1:

[ServiceContract]
public interface IService1
{
    [WebGet(UriTemplate = "/{value}")]
    string GetData(string value);

Upvotes: 4

Views: 23804

Answers (2)

Justin Pihony
Justin Pihony

Reputation: 67065

Remove the / from {value} and make sure it is listed as an OperationContract. It should be:

[WebGet(UriTemplate = "{value}")]
[OperationContract]

The base URL will come through with the trailing slash, so you are really looking for http://localhost:8000/hello//help in the current code

Upvotes: 6

Bevan
Bevan

Reputation: 44307

A stab in the dark ... by default, arbitrary processes are not permitted to listen on network ports.

When IIS is installed, the account that runs IIS is given permission - if you want other applications run by other accounts (console applications, windows services) to be able to listen to a port, you need to grant the permission.

Check out the netsh add urlacl command as a starting point.

Upvotes: 0

Related Questions