Roy r

Roy r

  • NA
  • 64
  • 135.2k

How to Consume REST based WCF Service ?

Jan 19 2011 7:44 AM
Hello guys ,

I would like to crate REST based WCF service for my application .
For that I've added WebInvoke and WebGet attributes to my methods as shown below .

------------------------------------------------------------------------------------
public interface IStudentService
{
[WebInvoke(Method = "POST", UriTemplate = "students")]
[OperationContract]
int Add(StudentProperty objStudentEntity);

[WebGet(UriTemplate = "students")]
[OperationContract]
DataTable FetchStudent();

[WebInvoke(Method = "DELETE", UriTemplate = "students/{studId}")]
[OperationContract]
int DeleteStudent(string studId);


[WebGet(UriTemplate = "students/{studId}")]
[OperationContract]
string GetOneStudent(string studId);

}
------------------------------------------------------------------------------------

Now I can easily test WebGetMethods( FetchStudent,GetOneStudent) by Url . For example following url will be used to fetch all student.

http://localhost:2251/StudentSVC.svc/students


Questions :

1. How can I consume it in C sharp ? For example how can I Fetch all students form code behind using above service ?

2. How can I test and consume methods marked with WebInvoke attributes ? I want to add students by using above service.


If any one knows then please tell me , and if possible then plz give sample code.

-Thanks

Answers (1)