Thursday, December 15, 2011

ABC of WCF


ABC of WCF

WCF Service is a program that exposes a collection of Endpoints. Each Endpoint is a portal for communicating with the world.
All the WCF communications are take place through end point. End point consists of three components.

Address

Basically URL, specifies where this WCF service is hosted .Client will use this url to connect to the service. e.g
http://localhost:8090/MyService/SimpleCalculator.svc

Binding

Binding will describes how client will communicate with service. There are different protocols available for the WCF to communicate to the Client. You can mention the protocol type based on your requirements.
A binding has several characteristics, including the following:
  • Transport -Defines the base protocol to be used like HTTP, Named Pipes, TCP, and MSMQ are some type of protocols.
  • Encoding (Optional) - Three types of encoding are available-Text, Binary, or Message Transmission Optimization Mechanism (MTOM). MTOM is an interoperable message format that allows the effective transmission of attachments or large messages (greater than 64K).
  • Protocol(Optional) - Defines information to be used in the binding such as Security, transaction or reliable messaging capability
The following table gives some list of protocols supported by WCF binding.
Binding
Description
BasicHttpBinding
Basic Web service communication. No security by default
WSHttpBinding
Web services with WS-* support. Supports transactions
WSDualHttpBinding
Web services with duplex contract and transaction support
WSFederationHttpBinding
Web services with federated security. Supports transactions
MsmqIntegrationBinding
Communication directly with MSMQ applications. Supports transactions
NetMsmqBinding
Communication between WCF applications by using queuing. Supports transactions
NetNamedPipeBinding
Communication between WCF applications on same computer. Supports duplex contracts and transactions
NetPeerTcpBinding
Communication between computers across peer-to-peer services. Supports duplex contracts
NetTcpBinding
Communication between WCF applications across computers. Supports duplex contracts and transactions

Contract

Collection of operation that specifies what the endpoint will communicate with outside world. Usually name of the Interface

Wednesday, April 13, 2011

Performance optimization for XML query in SQL SERVER


As we all uses XML Query instead of row level query to insert/update bulk data into a database in order to achieve better performance. But when there is a large dataset having multilevel xml nodes, the performance degrade significantly.

While doing performance tuning in “AcceleRATE” I came across with “XML indexes” on an xml column.


Below is the step by step process to achieve this.

1. Create a temporary table with on identity column with primary key and one other column with xml datatype.

CREATE TABLE #OptimizedXML(id INT IDENTITY PRIMARY KEY, SurveyXML xml NOT NULL)



2. Create a primary XML index

CREATE PRIMARY XML INDEX PrimaryXMLIndex ON #OptimizedXML(SurveyXML)

3. Create a secondary XML index

CREATE XML INDEX

XMLDataStore_XmlCol_PATH ON #OptimizedXML(SurveyXML)

USING XML INDEX PrimaryXMLIndex FOR PATH

4. Now insert the values into a table
INSERT INTO #OptimizedXML VALUES(@SurveyXML)
5. Here we are ready to perform the same XML query with some tweak to achieve performance.

SELECT F.Manager.value('@fname','varchar(255)') as fname,

F.Manager.value('@lname', 'varchar(255)') as lname,

F.Manager.value('@title', 'varchar(255)') as title,

F.Manager.value('@email', 'varchar(255)') as email,

F.Manager.value('@domainid', 'int') as domainid,

F.Manager.value('@ID', 'int') as userid,

F.Manager.value('@encryptedmail', 'varchar(500)') as encryptedemail

FROM #OPtimizedXML X

cross apply X.SurveyXML.nodes('Surveys[1]/Survey/Manager') AS F(Manager)

By doing the above tweak, the query which was earlier taking more than 2 minutes to execute, now takes just 10-15 seconds.

Additionally, there are few points, which we need to keep in mind while using this approach.

We must have one primary key (clustered index) on a table; it is required to create a XML index.
There must be one primary xml index followed by one or more secondary xml indexes on xml column(s).
While querying the table, we have to use a cross apply on the node where in we want to fetch data.

Tuesday, January 25, 2011

JAVA Mock exam test paper with 25 most important and frequently asked questions with answers and explanation

 QUESTIONS

Q1public class Test1{

public static void main(String[] args)
{int arr[] = new int[3]; 
for(int i = 0;i < arr.length;i++){

System.out.println(arr[i]); 
}
 } }

What will be the output?
A1 0 0 0
A2 ArrayIndexoutOfBoundsException
A3 NullPointerException
A4 null null null


Q2 Which of the following are valid array declarations?
A1 int arr[] = new int[];
A2 float arr[10] = new fl
A3 double []arr = new double[10];
A4 None Of the Above.

Q3 public class Test3{
public void method(){
 System.out.println("Called");
}
public static void main(String[] args){
method();
}
}

What will be the output?
A1 "Called"
A2 Compiler
A3 Runtime
A4 Nothing

Q4 public class Test4{


public static void method(){
System.out.println("Called");

}


public static void main(String[] args)
{ Test4 t4 = null;
t4.method();
} }


What will be the output?

A1 "Called"

A2 Compiler

A3 Runtime Exception

A4 Nothing is printed in screen

Q5 public class Test5{
public void Test5()
{

System.out.println("Constructor1");
}
public Test5(){}
System.out.println("Constructor2");
public static void main(String[] args)
{
Test5 t5 = new Test5(); } }


What will be the output?
A1 "Constructor1"
A2 "Constructor2"
A3 "Constructor1""Constructor2"
A4 Compiler Errror

Q6 public class Test6{
public Test6()
{
this(4);
}
public Test6(byte var)
{


}
System.out.println(var);
public static void main(String[] args)
{
Test6 t6 = new Test6();
} }


What will be the output?
A1 4
A2 4 4
A3 Compiler Error
A4 Compiles and Runs without error

Q7 public class Test7{
public Test7(){}
public Test7(Test7 ref){
this (ref,"Hai");
}
public Test7(Test7 ref,String str)
{
 ref.Test7(str);
 System.out.println("Hi");
}
public void Test7(String str)
{ System.out.println(str); }
public static void main(String[] args){
Test7 t = new Test7();
Test7 t7 = new Test7(t);
 }
}

What will be the output?
A1 HI
A2 hai
A3 Hai Hi
A4 Hi Hai

Q8 Which of the following are valid Constructors?
A1 public Test8(){}
A2 private void Test8(){}
A3 protected Test8(int k){}
A4 Test8(){}

Q9 Which of the following are valid method declarations?