File system | HTTP |
it is used for website development | it is used for website development and hosting |
it will uses ASP.NET development server | it will uses iis web server |
virtual directory will not be created | virtual directory will be created in IIS Server |
for each website different port no will be used | for, the website run through http protocol same port no will be used. |
Saturday, July 5, 2014
File System vs Http
Friday, July 4, 2014
WCF WITH WINDOWS HOSTING
File ->New-> Project-WCF Service Library
Delete the files IService and Service
Go to App.Config and Delete the Following lines which is written in
<services>
</services>
Add New Item and Add WCF Service name as Jobs.cs
And click on Add , then two files will be created.
IJobs.cs
Jobs.cs
Add New Item->Job.cs
Write the following code in IJobs.cs
Write the following code in Job.cs
Write the following code in Jobs.cs
Click on Start Debugging
Now double on GetJobs() to check the method is working or not.
The following screen appears, Next click on Invoke
And check the check box and click on Ok .
And click on the button beside View and see the data.
Copy the Url of the Service Application
.
Client application
Select windows application
First add the service Reference
And paste the URL
And click on Go button
And click on Ok Button.
And design the form as follows
Write the following code in Form1.cs
private void button1_Click(object sender, EventArgs e)
{
ServiceReference1.JobsClient obj = new ServiceReference1.JobsClient();
DataSet ds = new DataSet();
ds = obj.GetJobs();
dataGridView1.DataSource = ds.Tables[0];
}
private void button2_Click(object sender, EventArgs e)
{
ServiceReference1.JobsClient obj = new ServiceReference1.JobsClient();
ServiceReference1.Job jobobj = obj.GetJobInfo(int.Parse(textBox1.Text));
textBox2.Text = jobobj.employeename;
textBox3.Text = jobobj.address;
}
Run and see the output
Windows Hosting in WCF
File-new Project-windows Service
Next Right Click on Add Installer
We have to add the reference of our WCF Service Library DLL in this service.
To do this, right click on the project in Solution Explorer and select Add Reference. For adding the dll in reference, select browse tab in the window that appears, and navigate to the folder where our WCF service library is located. In that location, the dll can be found inside the bin-> debug folder. When this dll is added, it is imported into the Windows service app.
Similarly we need reference of
System.ServiceModel
namespace because it is not available by default in Windows Service.We will get two processes
Service process installer
Service installer
Service.cs
public partial class Service1 : ServiceBase
{
ServiceHost sHost;
public Service1()
{
InitializeComponent();
}
protected override void OnStart(string[] args)
{
sHost = new ServiceHost(typeof(WcfServiceLibrary3.Jobs));
sHost.Open();
}
protected override void OnStop()
{
sHost.Close();
}
}
Registering the Service with Windows OS
Go to the design view of the Windows service, right click and click on Add Installer option.
When this is clicked, we get two processes – ServiceProcessInstaller and ServiceInstaller.
Click on ServiceProcessInstaller and set its account property to local system.
Now click on Service Installer properties
Now build the service once again. This will create an executable file.
Copy the path of this exe file location and open the containing folder from command prompt.
In that path write the command
InstallUtil WindowsService.exe
Which registers the service with Windows OS?
Once it is registered with Windows, we can see it in the services list.
(Control Panel > Administrative Tools > Services)
WCF SERVICE WITH HTTP
Service application
Select console Application
Note: run the visual studio in Admin Mode only.
First add a reference
System.serviceModel
Go to program.cs and write the following code
Add a new class with name Job.cs
Add another class with name Demo.cs and inherit the interface
Output
Service is created.
Client application.
Select console application
And first add the reference system.serviceModel
And write the following code in Program.cs
Add the namespace
using System.ServiceModel;
Now, run the service application first and then run the client application both should be in running only.
Thursday, July 3, 2014
Operator overloading
Operator overloading
You can redefine or overload most of the built-in operators available in C#. Thus a programmer can use operators with user-defined types as well. Overloaded operators are functions with special names the keyword operator followed by the symbol for the operator being defined. Like any other function, an overloaded operator has a return type and a parameter list.
classBox
{
privatedoublelength; // Length of a box
privatedoublebreadth; // Breadth of a box
privatedoubleheight; // Height of a box
publicdoublegetVolume()
{
returnlength * breadth * height;
}
publicvoidsetLength(doublelen)
{
length = len;
}
publicvoidsetBreadth(doublebre)
{
breadth = bre;
}
publicvoidsetHeight(doublehei)
{
height = hei;
}
// Overload + operator to add two Box objects.
publicstaticBoxoperator +(Box b, Box c)
{
Boxbox = newBox();
box.length = b.length + c.length;
box.breadth = b.breadth + c.breadth;
box.height = b.height + c.height;
returnbox;
}
}
classTester
{
staticvoidMain(string[] args)
{
Box Box1 = newBox(); // Declare Box1 of type Box
Box Box2 = newBox(); // Declare Box2 of type Box
Box Box3 = newBox(); // Declare Box3 of type Box
doublevolume = 0.0; // Store the volume of a box here
// box 1 specification
Box1.setLength(6.0);
Box1.setBreadth(7.0);
Box1.setHeight(5.0);
// box 2 specification
Box2.setLength(12.0);
Box2.setBreadth(13.0);
Box2.setHeight(10.0);
// volume of box 1
volume = Box1.getVolume();
Console.WriteLine("Volume of Box1 : {0}", volume);
// volume of box 2
volume = Box2.getVolume();
Console.WriteLine("Volume of Box2 : {0}", volume);
// Add two object as follows:
Box3 = Box1 + Box2;
// volume of box 3
volume = Box3.getVolume();
Console.WriteLine("Volume of Box3 : {0}", volume);
Console.ReadKey();
}
}
Output:
publicclassWidget
{
publicint_value;
publicstaticWidgetoperator +(Widget a, Widget b)
{
// Add two Widgets together.
// ... Add the two int values and return a new Widget.
Widgetwidget = newWidget();
widget._value = a._value + b._value;
returnwidget;
}
publicstaticWidgetoperator ++(Widget w)
{
// Increment this widget.
w._value++;
returnw;
}
}
classProgram
{
staticvoidMain()
{
// Increment widget twice.
Widgetw = newWidget();
w++;
Console.WriteLine(w._value);
w++;
Console.WriteLine(w._value);
// Create another widget.
Widgetg = newWidget();
g++;
Console.WriteLine(g._value);
// Add two widgets.
Widgett = w + g;
Console.WriteLine(t._value);
Console.ReadKey();
}
}
Output:
Subscribe to:
Posts (Atom)
Kubernetes
Prerequisites We assume anyone who wants to understand Kubernetes should have an understating of how the Docker works, how the Docker images...
-
Super aggregates: Are used to calculate aggregates of aggregates There are two super aggregates functions Roll Up Cube When there is a singl...
-
SOLID principles allows object oriented programming implementation in an efficient better way into project development S-->Single R...
-
With this example you can create pdf and print pdf. If You are using ASP.NET MVC , PDF can be created by using Rotativa Rotativa is a ...