Tuesday, 18 February 2014

WCF Fundamentals–Part 2

 

 

Programming Clients

image

 

 

image

 

 

 

image

 

 

 

image

 

 

 

image

 

 

 

Demo of Using ServiceUtil.exe

image

 

 

This is one way to get the WSDL information via IE

image

 

 

This is another way to get WSDL information via ServiceUtil with META data

image

 

 

image

 

 

 

This is another way to get WSDL information via ServiceUtil with MEX protocol

image

 

 

image

 

 

image

 

 

image

 

 

 

Demo of using Service Reference

 

image

 

 

image

 

 

image

 

 

 

image

 

 

 

image

 

 

image

 

 

 

 

Programming WCF Channels

 

image

 

 

 

image

 

 

 

image

 

 

image

 

 

 

image

 

 

 

image

 

 

 

image

 

 

 

Demo of Creating, Using, and Closing Channels

 

image

 

 

image

 

 

image

 

 

 

image

 

 

 

Demo of Using Proxy Class

 

image

 

 

 

 

image

 

 

 

image

 

 

 

image

 

 

 

Handling Exceptions at Client Side

 

image

 

 

 

image

 

 

 

Demo of Handling Exceptions

 

Client Code:

image

 

image

 

Service Code:

image

 

 

image

 

 

image

 

 

 

Demo of Using Asynchronous

image

 

 

image

 

 

image

 

 

image

 

 

 

image

 

 

 

Demo of Sharing Service Contract Assemblies

 

image

 

 

image

 

 

 

Demo of Using Meta Data Resolver

 

image

 

 

image

 

 

 

RESTful Services

 

Introduction to RESTful service

image

 

image

 

 

image

 

 

image

 

 

 

image

 

 

 

image

 

 

 

image

 

 

 

image

 

 

image

 

 

 

image

 

 

image

 

 

image

 

 

 

image

 

 

 

image

 

 

 

image

 

 

 

image

 

 

 

image

 

 

 

image

 

 

 

image

 

 

 

Demo of REST-ful Service implementation

image

 

image

 

image

 

image

 

 

 

image

image

image

 

 

image

 

 

image

 

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();

 


 


image


 


image


 


 


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();
}

 


image


 


 


JSON using WCF service

image


 


 



[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);
}

 


 


image


 


 


image


 


 


image


 


 


image


 


 


 


WEB Operation Context

 


image


 


 


 


Syndication Programming Model

 


image


 


 


image


 


 


 


AJAX Integration via JSON

 


image


 


 


image


 


 


image


 


 


image


 


 


 


image


 


 


 


image


 


 


 


image


 


 


image


 


 


image


 


 


 


image


 


 


 


 


WCF Security


image


 


 


image


 


 


Security Mode

image


 


image


 


image


 


 


Transport Security Protection Level

image


 


image


 


 


image


 


 


 


WCF Service Impersonation


image


 


 


 


WCF Windows Authentication


image


 


image


 


image


 


 


 


What is WCF RIA service?


image


 


 


image


 


image


 


 


image


 


image


 


image


 


 


 


How to Create WCF RIA Service

image


 


 


image


 


 


image


 


image


 


 


image


 


 


image


 


 


image


 


image


 


image


 


 


image


 


 


What's new in WCF 4.5 - Part 4


 


image


 


image


 


 


 


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