19 CEO Dashboard Examples for Business Leaders
Let's rewind to the 1990s. Data used to be stored on servers and CEOs relied on basic tools to make optimal decisions. No dashboards, nothing. When you use Power BI with a solid...
Kapil Panchal - November 18, 2020
Listening is fun too.
Straighten your back and cherish with coffee - PLAY !
Self-hosting is the simplest way to host your services and a Self-hosted is that it hosts the service in an application that could be a Console Application or Window Forms, etc.
Ways to host the WCF service.
WCF service has two types of zones.
Some steps to create live services.
There are three steps to communicate between WCF Client and service.
Now, let’s see the steps to create a project.
Open visual studio, and create new project. After project creation, open solution explorer and right-click on the project name and click Add -> New Item -> and select WCF Service Library, this will be creating two files here CompanyClass and ICompanyClass are those two files.
Now, we can add a Service contract and Data contract. Service contract for Operation contract and Data contract for data members.
Here is a Company class model.
using System; usingSystem.Collections.Generic; usingSystem.Linq; usingSystem.Runtime.Serialization; usingSystem.Text; usingSystem.Threading.Tasks; namespaceWCFExample { [DataContract] publicclassCompanyClass { [DataMember] publicstring CompanyName { get; set; } [DataMember] publicstring Address { get; set; } [DataMember] publicintCompanyYear{ get; set; } publicCompanyClass() { } } }
Now, add the Service contract and Operation contract.
using System; usingSystem.Collections.Generic; usingSystem.Linq; usingSystem.ServiceModel; usingSystem.Text; usingSystem.Threading.Tasks; namespaceWCFExample { [ServiceContract] publicinterfaceICompanyService { [OperationContract] IListcompanyClasses(); [OperationContract] voidUpdate(CompanyClass cc); } }
Now, we have to implement a service in our class.
using System; usingSystem.Collections.Generic; usingSystem.Linq; usingSystem.Text; usingSystem.Threading.Tasks; namespaceWCFExample { publicclassAddServices :ICompanyService { static ListcompanyClasses = new List () { newCompanyClass() {CompanyName="Ifour", Address="Thaltej", CompanyYear=30}, newCompanyClass() {CompanyName="TCS", Address="AgoraMall", CompanyYear=20}, newCompanyClass() {CompanyName="Tencent", Address="S.G.Highway", CompanyYear=10}, newCompanyClass() {CompanyName="TensorFlow", Address="Sola", CompanyYear=15}, newCompanyClass() {CompanyName="Stridly", Address="Shivranjani", CompanyYear=14}, }; publicvoidUpdate(CompanyClass cc) { var data = companyClasses.FirstOrDefault(s =>s.CompanyName == cc.CompanyName); if (data!=null) { data.Address = cc.Address; data.CompanyYear = cc.CompanyYear; } } publicIList Classes() { returncompanyClasses; } } }
usingSystem.ServiceModel; usingSystem.ServiceModel.Description; publicstaticvoid Main(string[] args) { using (ServiceHost host = newServiceHost(typeof(AddServices))) { ServiceMetadataBehaviorserviceMetadata =newServiceMetadataBehavior { HttpGetEnabled = true }; host.Description.Behaviors.Add(serviceMetadata); host.AddServiceEndpoint(typeof(AddServices), newNetTcpBinding { Security = { Mode = SecurityMode.None } }, nameof(AddServices)); host.Open(); Console.WriteLine("Services are hosted successfully."); Console.WriteLine("Press any key to stop the services."); Console.ReadKey(); } }Step: 4
All Services are ready to host. Now, run your project and check your services are hosted successfully and you can get one service URL.
Now, we can create a WPF project for creating a client and consuming their services.
Create a new project for WPF Windows Application and use services using the MVVM pattern.
First of all, we have to create a proxy channel for the WCF Company service. Using this proxy object, we can get the service data that we want.
Let’s see how to create a proxy and get the data from the server.
using System; usingSystem.Collections.Generic; usingSystem.Linq; usingSystem.ServiceModel; usingSystem.Text; usingSystem.Threading.Tasks; namespaceWCFExample { publicclassProxyServiceStep: 6whereT :class { private T _GetT; public T GetT(string path) { return _GetT ?? (_GetT = ServiceInstance(path)); } privatestatic T ServiceInstance(string path) { varbindpath = newNetTcpBinding(); bindpath.Security.Mode = SecurityMode.None; EndpointAddressendpointAddress = newEndpointAddress(path); returnChannelFactory .CreateChannel(bindpath, endpointAddress); } } }
After setting the proxy channel, create a folder and give it the name view model for the Company models and binding it with the Xaml.
using System; usingSystem.Collections.Generic; usingSystem.Collections.ObjectModel; usingSystem.Linq; usingSystem.Text; usingSystem.Threading.Tasks; usingSystem.Windows.Input; namespaceWCFExample.ViewModel { publicclassCompanyViewModel { privatereadonlyICompanyServicecompanyService; publicCompanyViewModel() { ListData = newObservableCollection(); varProxyservices = newProxyService (); companyService = Proxyservices.GetT("net.tcp://localhost:9950/CompanyService"); var companies = companyService.companyClasses(); foreach (var company in companies) { ListData.Add(newCompaniesViewModel(company, this)); } } publicObservableCollection ListData{ get; set; } publicvoidUpdateProperty(CompaniesViewModelcompaniesViewModel) { companyService.Update(companiesViewModel.Model); } } publicclassCommands :ICommand { private Action
Now, add one more view model for representing every detail of the Company. In this view model we implicit INotifyPropertyChanged for an instant update.
usingJetBrains.Annotations; using System; usingSystem.Collections.Generic; usingSystem.ComponentModel; usingSystem.Linq; usingSystem.Runtime.CompilerServices; usingSystem.Text; usingSystem.Threading.Tasks; namespaceWCFExample.ViewModel { publicclassCompaniesViewModel :INotifyPropertyChanged { public Commands EventHandler{ get; privateset; } privatereadonlyCompanyViewModel _base; privatestring address; privateint year; publicCompanyClass Model; publicstring Address { get{ return address; } set { if(address != value) { address = value; Model.Address = value; _base.UpdateProperty(this); OnPropertyChanged(nameof(Address)); } } } publicint Year { get{ return year; } set { if(year != value) { year = value; Model.CompanyYear = value; _base.UpdateProperty(this); OnPropertyChanged(nameof(Year1)); OnPropertyChanged(nameof(Year2)); OnPropertyChanged(nameof(Year3)); OnPropertyChanged(nameof(Year4)); OnPropertyChanged(nameof(Year5)); } } } publicbool Year1 =>Model.CompanyYear>= 30; publicbool Year2 =>Model.CompanyYear>= 20; publicbool Year3 =>Model.CompanyYear>= 10; publicbool Year4 =>Model.CompanyYear>= 15; publicbool Year5 =>Model.CompanyYear>= 14; publicCompaniesViewModel(CompanyClass company, CompanyViewModel companies) { Model = company; EventHandler = new Commands(OnClickYear); _base = companies; address = company.Address; year = company.CompanyYear; } privatevoidOnClickYear(objectobj) { this.Year = int.Parse(obj.ToString()); } publiceventPropertyChangedEventHandlerPropertyChanged; [NotifyPropertyChangedInvocator] protectedvirtualvoidOnPropertyChanged([CallerMemberName] stringpropertyName = null) { PropertyChanged?.Invoke(this, newPropertyChangedEventArgs(propertyName)); } } }
Self-hosting in WCF is easy to use you can make your service running using a few lines of code, you can control your service through the Open () and Close () methods of ServiceHost. Window Communication Foundation is a reliable, secure, and scalable messaging platform for the .NET framework, and have some other features like Security, Data Contract, Service Oriented, Transaction, etc.
Build Your Agile Team
Let's rewind to the 1990s. Data used to be stored on servers and CEOs relied on basic tools to make optimal decisions. No dashboards, nothing. When you use Power BI with a solid...
Imagine walking into a meeting where critical decisions need to be made—fast. You need clear, flexible data that you can analyze on the spot. But what if your insights are locked inside...
Clear insights mean smarter decisions, and this is what data storytelling does. It helps you speak a language that you quickly understand. Like for example, you are a CTO dealing with...