.Net Framework, Asp.net, Ado.net, .Net Remoting, .Net Webservice, SQL, XML, XSLT, WCF, WPF, WWF NHibernate, Ajax, Jquery, DHTML

Ado.netAsp.Net 2.0SQLC-SharpXMLFrameworkIISXMLWebServiceArchitecture
UMLProject ManagementSDLCMethodologiesDesign PatterenOOPWCF.Net RemotingWWF
MVPMVCSilver LightN-HibernateAjaxJ-QuerySEO-MarketingSite MapPhp

WCF (Windows Communication Foundation)

WCF (Windows Communication Foundation) is a SDK / Framework for developing & deploying application on windows , It provides a manageable approach to distributed development environment. Let's look at the common questions and answers of WCF.

Now we look at the implementation step by step.
Windows Communication Foundation
Here i share a WCF implementation structure with a web application, the structure are devided into 3 solutions with 6 assemblies, this can be changed as per requirement. As you can see the structure above.
We have expert WCF developer in mumbai india, Please contact us to know more about our service.
Here we look how to create a Host, Host could be either a "console application" or a "Winform Application", so now we create a winform application with name "HostService", this application will have 2 functions, Start and Stop Service. Host can use either Tcp / Http channel
Host Start/Stop (a Win application)
using System.Windows.Forms;
1:using System.ServiceModel;
2:namespace HostService
3:{
4: public partial class frmHost : Form
5: {
6: private ServiceHost host = null;
7: private string urlMeta, urlService = "";
8: private List<ServiceHost> objHostList;
9:
10: public frmHost()
11: {
12: InitializeComponent();
13: }
14:
15:
16: private enum ServicePort
17: {
18: //here we can allocate port for each module.
19: Module1 = 8020,
20: Module2 = 8021
21:
22: }
23:
24: private void btnStartService_Click(object sender, EventArgs e)
25: {
26: // this can be pickedup from app.config also
27: OpenHost(typeof(ServiceAgent.Module1.RoomAgent), typeof(ServiceAgent.Module1.IRoomAgent), ServicePort.Module1);
28: }
29:
30: void OpenHost(Type Service, Type IService, ServicePort portnumber)
31: {
32: try
33: {
34:
35:
36: // Returns a list of ipaddress configuration. use system.net
37: IPHostEntry ips = Dns.GetHostEntry(Dns.GetHostName());
38:
39: // Select the first entry. I hope it's this maschines IP
40: IPAddress _ipAddress = ips.AddressList[0];
41: string sPort = Convert.ToString((int)portnumber);
42: string sPortName = portnumber.ToString();
43: string sMetaPort = Convert.ToString(((int)portnumber) + 1);
44:
45: // Create the url that is needed to specify where the service should be started
46: urlService = "net.tcp://" + _ipAddress.ToString() + ":" + sPort + "/" + sPortName;
47:
48: NetTcpBinding httpBinding = new NetTcpBinding();
49:
50:
51: host = new ServiceHost(Service);
52: host.Opening += new EventHandler(hostOpening);
53: host.Opened += new EventHandler(hostOpened);
54: host.Closing += new EventHandler(hostClosing);
55: host.Closed += new EventHandler(hostClosed);
56: host.AddServiceEndpoint(IService, httpBinding, urlService);
57:
58: objHostList.Add(host);
59:
60: host.Open();
61: }
62: catch (Exception ex)
63: {
64: txtStatus.Text += ex.ToString();
65: }
66: }
67:
68: private void btnStopService_Click(object sender, EventArgs e)
69: {
70: host.Close();
71: }
72:
73:
74: }
75:}
76:
Now we create a ServiceAgent for Host, for each module we have a separate folder (ex. "Module1"), inside that we have a agent interface which will contain all defination (here "IRoomAgent") and a class which will have implementation (here "RoomAgent")
Service Agent to connect to Host
using System;
1:using System.Collections.Generic;
2:using System.Linq;
3:using System.Text;
4:using BusinessEntity;
5:using System.ServiceModel;
6:
7:
8:namespace HostServiceAgent.Module1
9:{
10:
11: // agent defination
12:
13: [ServiceContract()]
14: public interface IRoomAgent
15: {
16: [OperationContract()]
17: Room CreateRoom(Room room);
18:
19: [OperationContract()]
20: Room GetRoom(int roomId);
21:
22: }
23:
24:
25: // agent implementation
26: [ServiceBehavior(InstanceContextMode =InstanceContextMode.PerCall, ConcurrencyMode = ConcurrencyMode.Single)]
27: public class RoomAgent : IRoomAgent
28: {
29:
30: #region IRoomAgent Members
31:
32: public Room CreateRoom(Room room)
33: {
34: throw new NotImplementedException();
35: }
36:
37: public Room GetRoom(int roomId)
38: {
39: throw new NotImplementedException();
40: }
41:
42: #endregion
43: }
44:
45:
46:}
47:
Leave your comment.
Name
Email
Comments
Tell Us2479+5 =

Reduce your Dialy IT Cost, Consult with us
Stay healthy in recession

Advertisement
Sponsored by

Privacy Policy ©2009 ETG Consultancy, All Rights Reserved Terms & Conditions
Asp.net, Ado.net, .Net Remoting, .Net Webservice, SQL, XML, XSLT, WCF, WPF, WWF NHibernate, Ajax, Jquery, DHTML