Hosting service on IIS Vs Console Applications

21 September, 2018


Related Blogs

Difference between hosting the service on IIs and in console applications

  • When we host the service at IIS, IIS will start the service automatically whenever the request is coming from the host and executes the service and sends the result back to client application.
  • But when we host the service using console application and we want to consuming from client we need to keep service running manually.
  • The service hosted using IIS will support only http protocol. Where as the service running or hosted in console application will also support TCP protocol


Differences between basic HTTP binding and WS HTTP sending

originally WS http binding is the combination of basic http binding and web services as well as web services extension. This can be written as, WS http binding = Basic http Binding + WS - *  

Basic http binding WS http Binding
Data is transferred in plain text form between client and service component Data is transferred in encrypted form between client and service component
Supports all versions of supports 3.0, 3.5 and 4.0 versions of ASP.Net
Supports backward compatibility i.e., service can be consumed from the client applications created in 2.0 versions. Doesn’t support backward compatibility i.e., service can’t be consumed form the client applications created in 1.0, 1.1&2.0 versions.
Basic http binding follows SOAP 1.1 version WS http binding follows SOAP 1.2 version;
Security is not good. security is good.


Hosting a WCF service using windows service

Create a new window service with the name Example 7 11 change service 1.cs file name to sample service.cs 11 add reference to system. Service model name space 11 write the following code using system. Service model; namespace example7 { [service contract] public interface IMath numbers { [operation contract] int square (int x); [operation contract] int cube (int x); [operation contract] int factorial (int x); } Public partial class sumpleservice – service base, Imc dhnumbers Servicehost objs = null; Protected override void onstart (--) { obj = new service host (type of (sample service)); if (objs ! = null) objs. Opern(); } protected override void onstop(--) { if (objs! = null) { objs.close(): objs=null; } } public int squar (int x) { return x * x; } public int cube (int x) { public int factorial (int x) { return x*x*x; } public int factorial (int x) { int R = 1, I; for (i=1; i<=x;i++) { R=R * i } return R; } } 11Add new app.config into the windows service 11 write the following code <configuration> <system.service Model> <service> <Service name = “Example 7 . sample service” behavior configuration = “Metadata support”> <host> <base addresses> <add base address = “net.tcp:// localhost : 8001/Example 7”/> <add base address = “http:// localhost:8081/Example7”/> </base addresses> </hot> <end point address = “Tcpmex” binding = “meretcp binding” contract = “metadata Exchange”/> <endpoint address = “ ” binding = “ws http binding” contract = “Example7. Imath numbers”/> </service> </services> <behaviors> <services behaviors> <behavior name = “metadatasupport”> <Service metadata http get enabled = “False” http sget url = “”/> </behavior> </service behaviors> </behaviors> </system.service model></configuration> Go to sample service cs design11click with right mouse button 11 click on add installer 11this will add service process Installer and service installer classes to the application 11 select serviceprocess Installer11 go to properties window, set the following properties according to local system 11 select service installer à go to properties window, set the following properties service name 11 sample service display name 11 sample service start type 11 automatic 11build the application (this will generate an exe) 11Go to visual studio 2008 command prompt to install the windows service in control panel service 11Change the disk location TC Excample 7 exe location type the following command i-e., Install util.exe - ; example 7. Exe This will install the service with in the control panel services. Go to control panel services 11 select the sample service 11 click with right mouse button 11 click on start  11service will be started. Now this service is ready and can be consumed from any client application  

Sample of create client application to consume the WCF service hosted using windows service

Name check example 7   Screenshot_75     11Design the form 11 go to solution explorer 11 select the solution11 click with right mouse button 11 click on add service reference 11 type the following address net.tcp//localbost : 8001/ example 7/tcpmex 11 change the service reference 1 to sr1 11 click on ok (This coil) create proxy component) 11 write the following code for calculate button protected void btn calculate _click(---) { SRI. Sample service client obj 1 = new SR1. Sample service client(); int a = convert. TOInt32 (txtnum.text): lblsquare text = obj1. Square (a). tostraing(); lblcube. Text =obj1. Cube ()a . tostring(); Lblfactorial . text = obj1. Factorial (a). tostring(); } 11when we are hosting the service at IIS, the service need not be continuously running rather when ever any client sends request, IIS will execute the service and sends, the result back to the client 11Whenever WCF service is hosted at IIS, the execution of the service will be under the control of IIS 11Whenever service is hosted with in console applications we should be always running as long as any client is consuming that service 11when we host the WCF service using console applications, the service will run under the control of CLR with the help of OS. 11When we host the WCF service using windows services the service starts running whenever operating system is started. 11Any client can consume this service until this is stopped manually (or) system is shutdown 11When the service is hosted using windows service it will run under the control of operating system with the help of CLR    

About Author


Author Bio

TekSlate is the best online training provider in delivering world-class IT skills to individuals and corporates from all parts of the globe. We are proven experts in accumulating every need of an IT skills upgrade aspirant and have delivered excellent services. We aim to bring you all the essentials to learn and master new technologies in the market with our articles, blogs, and videos. Build your career success with us, enhancing most in-demand skills .