I Love Stackoverflow
I Love Stackoverflow

Reputation: 6868

How to call endpoint using routing table in wcf?

I have created 1 demo web application in which i am trying to consume wcf service which contains no svc file.Basically i am trying to add routes to routetable like we add in asp.net mvc.

I have taken reference from here :Reference

Code :

 [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
    public class PersonService : IPersonService
    {
        [WebInvoke(UriTemplate = "", Method = "GET")]
        public void GetPerson()
        {
            string k = "a";
        }
    }

 [ServiceContract]
    public interface IPersonService
    {
        [OperationContract]
        void GetPerson();

    }

 public class Global : System.Web.HttpApplication
    {
        protected void Application_Start(object sender, EventArgs e)
        {
            RouteTable.Routes.Add(new ServiceRoute("foo", new WebServiceHostFactory(), typeof(PersonService)));
        }
    }

Web.config :

<system.serviceModel>
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true"/>
    <standardEndpoints>
      <webHttpEndpoint>
        <standardEndpoint name="" helpEnabled="true" automaticFormatSelectionEnabled="true"/>
      </webHttpEndpoint>
    </standardEndpoints>
  </system.serviceModel>

when i try to call my GetPerson method from browser then i am getting EndPoint not found. enter image description here

Can anybody please help me with this?

Upvotes: 0

Views: 428

Answers (1)

I Love Stackoverflow
I Love Stackoverflow

Reputation: 6868

Ok i manage to solve it by providing name of my method in Uritemplate like below :

[WebInvoke(UriTemplate = "GetPerson", Method = "GET")]
        public void GetPerson()
        {
            string k = "a";
        }

Upvotes: 0

Related Questions