Language Integrated Query (LINQ) is a great tool shipped with .net framework 3.5. With LINQ you can achieve a lot more functionality and save a lot of your development time.
What LINQ support?
LINQ to SQL Server: With LINQ you can directly connect to SQL server and write down your queries in C#. When you use LINQ to SQL classes, LINQ will automatically generate classes for your tables in the SQL server.
LINQ to XML: With LINQ to XML you can achieve XML programming in .Net framework.
LINQ to Dataset: With LINQ to Dataset you can connect LINQ to ADO.Net Databases
LINQ to Objects: With QINQ to Objects you can achieve any query on the collection of objects. This can help you to avoid loop for multiple conditions over a collection. You can use LINQ to Objects over Array, List etc.
Asp.net has many validation controls availables as native controls.this is the great way of validating INPUT controls at both client side and server side.
some peoples hate this validation controls because they think that they are less managable from client side.but this is not true.
when you drop validation controls on the page and see SOURCE of that page. you can see that all validation stuff is shipped as normal javascript variables. thus we can manage them from javascript easily.
i will show some useful methods/function in JAVASCRIPT which may be handy for us while using validation controls .
(1) How to disable all validators:
function DisaableAllValidators(sender) {
var AllValidattors = new Array();
AllValidators = Page_Validators;
for (var i = 0; i < AllValidators.length; i++) {
ValidatorEnable(AllValidators[i], false);
}
}
Here Page_Validatorsis Asp.net generated array of validators.we can manipulate as we want in out javascript functions.
Here Page_ValidationSummaries is the Array of all validation summaries dropped on the page.you can manupulate all summaries using this array.
(4) Hide All validation messages:
function HideAllValidators() {
var AllValidattors = new Array();
AllValidators = Page_Validators;
for (var i = 0; i < AllValidators.length; i++) {
if (AllValidators[i].display == 'Dynamic') {
AllValidators[i].style.display = 'none';
}
else {
AllValidators[i].style.visibility = 'hidden';
}
}
}
(5)Force All validations to fired:
function ForceAllValidation() {
alert(Page_ClientValidate());
}
Here Page_ClientValidate() is the built-in function which is responsible to validate all validation controls on the page.
it accepts validationGroup as argument to validate fire validation for particular validation group only.
(6)Force Single Validation to fired!:
function ForceSingleValidation() {
var tmpvalRequireMobile = document.all ? document.all["valRequireMobile"] : document.getElementById("valRequireMobile");
ValidatorValidate(tmpvalRequireMobile);
alert(tmpvalRequireMobile.isvalid);
}
Here valRequireMobile Is ClientID of validator control and ValidatorValidate() is Built-in function which is accept validation control as argument and validate whether is is valid or not.
Thus,we can use Clientside validation library of validation controls to manepulate validation controls in custom javascript functions.
There is new baby of microsoft in the world. called WCF service. But there is huge Question how to call it in webapplication. thoug it is as easy as we are doing with webservice.
there is a huge differance in the plateform on which webservice is built and on which WCF is service in built.
Differance:
The Main differance bet'n this two services (WebService/WCF) is With WCF Service SOAP messages can be transmitted over a variety of supported protocols including IPC (named pipes), TCP, HTTP and MSMQ. Like any distributed messaging platform,on the other hand in WebService SOAP message can only transmitted via HTTP.
How To Create WCF Service:
To Create WCF service Create
1).Create blank website 2).Right-Click > Add Item >WCF Service 3). Add referance to System.ServiceModel.
Three files will be created in solution .
A) App_Code/IService.cs
Content:
using System.ServiceModel;// NOTE: If you change the interface name "IService" here, you must also update the reference to "IService" in Web.config. [ServiceContract] publicinterfaceIService { [OperationContract] string DoWork();
}
B) App_Code/Service.cs
Content:
using System;
using System.ServiceModel.Activation; // NOTE: If you change the class name "Service" here, you must also update the reference to "Service" in Web.config. [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Required)] publicclassService : IService { publicstring DoWork() {
This are the steps to create WCF service.To call WCF service in our application we have to Add bindings in web.Config file & also have to create a class which acts as proxy of WCF service in our application.
How to Consume WCF service in WebApplication:
to call WCF service we have to add following service contract in our web.config file. please copy and paste below configuration tags between <system.serviceModel> </system.serviceModel> elements.
Now we have done with configuration of WCF service configuration.now we have to create ClassLibrary which contains proxy class to call WCF service methods.
Steps to create proxy is:
1) on solution Right-Click >Add New Project >Class Library.
2) Add Class and name it ServiceCaller.cs.
3) Add Referance to System.ServiceModel in Class Library project.
Finally now we are done with creating WCF service caller class.I have given sample code for service proxy and configuration elements.But you can also create configuration Using Command line Called svcutil.exe Automatically.
Steps to create configuration and proxy class using Command-line(svcutil.exe):
you can find more details of each and every class and terms and Namespace used here in following links.also can find more about making WCF service more secure from the referances given here.
With the release of .Net framework 3.5 they shipped a good way of communication with webservice.
Web service was also available in old version of .Net, but there was a lack of mechanism using which we can call web service using JavaScript. This new way of calling web service in JavaScript also called script services.
Web Method/Script Method:
As in web service we add [webmethod] attribute, t o call same web method in JavaScript you have to add [scriptmethod] attribute on the method.
[System.Web.Script.Services.ScriptMethod]
publicstring HelloWorld()
OR to make all method in the particular web service you can add [ScriptService] attribute above definition of web service.
It is simple to add web service using visual studio. When you add web service default template will be added in the solution. To make this web service to behave as scriptservice add Attribute [System.Web.Script.Services.ScriptService] on the WebService.cs Class.
How to consume web service (Script Service) using JavaScript:
To use webservice add referance of WebService.asmx to ScriptManager.
How to consume web service (Script Service) Having SOAP Header using JavaScript:
For enhancing Security of the webservice some time we have to pass some sensitive information.
We have to pass this information in essence to call that method regardless of from where you are consuming it. It may from JavaScript or Server side code or in any other application.
And this is the method protected with that SOAP Header.
[WebMethod]
[SoapHeader("objAuthHeader")]
publicList<Company> GetEmployees()
{
if (objAuthHeader.Password == "MyPassword")
{
//Do Sensitive process
}
}
To Call this method we can use below code.
localhost.WebService wc = new localhost.WebService();
wc.AuthHeaderValue = new localhost.AuthHeader();
wc.AuthHeaderValue.UserName = "MyName";
wc.AuthHeaderValue.Password = "MyPassword";
wc.GetEmployees();
How to set SOAP Header from Javascript/Client Side code;
We have to create a request object in SOAP format with header value in it and then we have to send it to the server.in response thet soap request server will return result in XML Document format.to utilize output we have to process thet document in javascript.
Here is the requestTemplate:
function CallprotectedService() {
var requestTemplate = '<?xml version=\"1.0\" encoding=\"utf-8\"?>' +