Programming Clients
Demo of Using ServiceUtil.exe
This is one way to get the WSDL information via IE
This is another way to get WSDL information via ServiceUtil with META data
This is another way to get WSDL information via ServiceUtil with MEX protocol
Demo of using Service Reference
Programming WCF Channels
Demo of Creating, Using, and Closing Channels
Demo of Using Proxy Class
Handling Exceptions at Client Side
Demo of Handling Exceptions
Client Code:
Service Code:
Demo of Using Asynchronous
Demo of Sharing Service Contract Assemblies
Demo of Using Meta Data Resolver
RESTful Services
Introduction to RESTful service
Demo of REST-ful Service implementation
Uri httpUrl = new Uri("http://localhost:8090/MyService/EmployeeService");
WebServiceHost host = new WebServiceHost(typeof(MyFirstRESTfulService.EmployeeService), httpUrl);
host.Open();
foreach (ServiceEndpoint se in host.Description.Endpoints)
Console.WriteLine("Service is host with endpoint " + se.Address);
//Console.WriteLine("ASP.Net : " + ServiceHostingEnvironment.AspNetCompatibilityEnabled);
Console.WriteLine("Host is running... Press < Enter > key to stop");
Console.ReadLine();
Step 8:Now we can start with client application. For this example we can create a console application to read the employee information and add new employee to the server resource. Below code first read the employee details from the server and add new employee and once again it read the employee details to confirm the added resource.
WebChannelFactory < IEmployeeService > cf =
new WebChannelFactory< IEmployeeService >(
new Uri("http://localhost:8090/MyService/EmployeeService"));
IEmployeeService client = cf.CreateChannel();
var d = client.GetEmployee(1);
//Load all the Employee from the server and display
foreach (Employee e in client.GetAllEmployeeDetails() )
{
Console.WriteLine(string.Format("EmpID:{0}, Name:{1} {2}",e.EmpId ,e.Fname ,e.Lname ));
}
//Add new user
client.AddEmployee(new Employee() { EmpId = 11, Fname = "John", Lname = "J", JoinDate = new DateTime(2010, 7, 24), Age = 34, Salary = 10000, Designation = "Software Engineer" });
Console.WriteLine("******************After adding new user ****************");
//Load all the Employee from the server and display
foreach (Employee e in client.GetAllEmployeeDetails() )
{
Console.WriteLine(string.Format("EmpID:{0}, Name:{1} {2}",e.EmpId ,e.Fname ,e.Lname ));
}
Console.ReadLine();
}
JSON using WCF service
[ServiceContract()]
public interface IEmployeeService
{
[WebGet(UriTemplate = "Employee", ResponseFormat=WebMessageFormat.Json )]
[OperationContract]
List < Employee > GetAllEmployeeDetails();
[WebGet(UriTemplate = "Employee?id={id}", ResponseFormat = WebMessageFormat.Json)]
[OperationContract]
Employee GetEmployee(int Id);
[WebInvoke(Method = "POST", UriTemplate = "EmployeePOST", ResponseFormat = WebMessageFormat.Json, RequestFormat = WebMessageFormat.Json)]
[OperationContract]
void AddEmployee(Employee newEmp);
[WebInvoke(Method = "PUT", UriTemplate = "EmployeePUT", ResponseFormat = WebMessageFormat.Json, RequestFormat = WebMessageFormat.Json)]
[OperationContract]
void UpdateEmployee(Employee newEmp);
[WebInvoke(Method = "DELETE", UriTemplate = "Employee/{empId}", ResponseFormat = WebMessageFormat.Json)]
[OperationContract]
void DeleteEmployee(string empId);
}
WEB Operation Context
Syndication Programming Model
AJAX Integration via JSON
WCF Security
Security Mode
Transport Security Protection Level
WCF Service Impersonation
WCF Windows Authentication
What is WCF RIA service?
How to Create WCF RIA Service
What's new in WCF 4.5 - Part 4
Blogger Labels: Fundamentals,Part,Clients,Demo,ServiceUtil,WSDL,information,META,data,protocol,Service,Reference,Channels,Proxy,Class,Exceptions,Client,Side,Code,Asynchronous,Contract,Assemblies,Resolver,RESTful,Services,Introduction,REST,implementation,MyService,EmployeeService,WebServiceHost,MyFirstRESTfulService,Open,ServiceEndpoint,Description,Endpoints,Console,WriteLine,ServiceHostingEnvironment,Host,Enter,ReadLine,Step,example,employee,server,resource,WebChannelFactory,IEmployeeService,CreateChannel,GetEmployee,Load,GetAllEmployeeDetails,Format,EmpID,Name,Fname,Lname,user,AddEmployee,John,JoinDate,DateTime,Salary,Designation,Software,Engineer,JSON,ServiceContract,interface,WebGet,UriTemplate,ResponseFormat,WebMessageFormat,OperationContract,List,Method,POST,EmployeePOST,RequestFormat,EmployeePUT,UpdateEmployee,DELETE,DeleteEmployee,Operation,Context,Syndication,Model,AJAX,Integration,Mode,Transport,Protection,Level,Impersonation,Windows,Authentication,Create,httpUrl,localhost,foreach,newEmp
No comments:
Post a Comment