none
How client can know about wcf rest service method's endpoint's RRS feed

  • Question

  • Hai All,

    I am new to wcf rest servicess,

     public interface IRestService
        {
            [WebGet(UriTemplate="/Student",
                ResponseFormat=WebMessageFormat.Json
                )]
            [OperationContract]
            List<Product> GetProducts();

            [WebInvoke(Method="GET",UriTemplate = "/GetStudent/{Id}", RequestFormat = WebMessageFormat.Json,
                ResponseFormat = WebMessageFormat.Json)]
            [OperationContract]
            List<Product> GetData(string Id);

            [WebInvoke(Method = "POST", UriTemplate = "/Insert", RequestFormat = WebMessageFormat.Json,
                ResponseFormat = WebMessageFormat.Json
             )]
            [OperationContract]
            bool insert(Product Product);


            [OperationContract]
            [WebGet(UriTemplate = "/Add/{Number1}/{Number2}", RequestFormat = WebMessageFormat.Json,
            ResponseFormat = WebMessageFormat.Json
            )]
            int Add(string Number1, string Number2);

        }

    public class RestService : IRestService
        {
            public List<Product> GetProducts()
            {
                PractiseEntities db = new PractiseEntities();
               
                var students = from p in db.StudentEntities select p;
                List<Product> st1 = students.ToList().ConvertAll(new Converter<StudentEntity, Product>(TranslateStudentEntityToStudent1));

                return st1;

                

            }
            public List<Product> GetData(string Id)
            {
                int id = Convert.ToInt32(Id);
                PractiseEntities db = new PractiseEntities();
                var stdnts = from p in db.StudentEntities
                             where p.ID == id
                             select p;
                List<Product> st = stdnts.ToList().ConvertAll(new Converter<StudentEntity, Product>(TranslateStudentEntityToStudent1));
                return st;
            }
            private Product TranslateStudentEntityToStudent1(StudentEntity student)
            {
                Product p = new Product();
                p.ProductID = student.ID;
                p.ProductName = student.Name;
                p.QuantityPerUnit = student.Adress;
                p.UnitPrice = student.DOB;
                return p;

            }
            public bool insert(Product product)
            {
                PractiseEntities db = new PractiseEntities();
                StudentEntity st = productToStudent(product);
                db.StudentEntities.AddObject(st);
                db.SaveChanges();
                return true;
            }
            private StudentEntity productToStudent(Product p)
            {
                StudentEntity s = new StudentEntity();
                s.ID = p.ProductID;
                s.Name = p.ProductName;
                s.Adress = p.QuantityPerUnit;
                s.DOB = p.UnitPrice;
                return s;
            }

           public int Add(string Number1, string Number2)
            {
                int num1=Convert.ToInt32(Number1);
                int num2 = Convert.ToInt32(Number2);
                return num1 + num2;
            }
        }


    srujana

    Tuesday, April 9, 2013 8:12 AM

Answers

  • RESTFul service can be accessed using browser during development phase. 

    Client interacts with the service through endPoint (Example: http://localhost:XXXX/restservice)

    Refer 'consuming the service' part of this article 

    http://www.codeproject.com/Articles/255684/Create-and-Consume-RESTFul-Service-in-NET-Framewor


    Apriori algorithm [association rule]

    Tuesday, April 9, 2013 8:56 AM
  • Hi,

    To call the service from a client app, you need define a client endpoints that matches with service side in the client's app.config file. For example.

    Service's config file

    <service name="Servicenamespace.EmployeesService">
                    <endpoint address="http://127.0.0.1:5451/testservice" 
                              binding="webHttpBinding" 
                              contract="Servicenamespace...IEmployeesService"/>
                </service>

    Client's App.config

    <client>
          <endpoint name="employeeService"
                    address="http://127.0.0.1:5451/testservice" 
                    behaviorConfiguration="webBehavior"
                    binding="webHttpBinding" 
                    contract="Servicenamespace...IEmployeesService"/>
        </client>

    Best Regards.


    Haixia
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Wednesday, April 10, 2013 10:14 AM
    Moderator

All replies

  • RESTFul service can be accessed using browser during development phase. 

    Client interacts with the service through endPoint (Example: http://localhost:XXXX/restservice)

    Refer 'consuming the service' part of this article 

    http://www.codeproject.com/Articles/255684/Create-and-Consume-RESTFul-Service-in-NET-Framewor


    Apriori algorithm [association rule]

    Tuesday, April 9, 2013 8:56 AM
  • Hi,

    To call the service from a client app, you need define a client endpoints that matches with service side in the client's app.config file. For example.

    Service's config file

    <service name="Servicenamespace.EmployeesService">
                    <endpoint address="http://127.0.0.1:5451/testservice" 
                              binding="webHttpBinding" 
                              contract="Servicenamespace...IEmployeesService"/>
                </service>

    Client's App.config

    <client>
          <endpoint name="employeeService"
                    address="http://127.0.0.1:5451/testservice" 
                    behaviorConfiguration="webBehavior"
                    binding="webHttpBinding" 
                    contract="Servicenamespace...IEmployeesService"/>
        </client>

    Best Regards.


    Haixia
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Wednesday, April 10, 2013 10:14 AM
    Moderator