Thursday, December 30, 2010

WCF Interview Questions

What is WCF?

WCF stands for Windows Communication Foundation. It is a Software development kit for developing services on Windows. WCF is introduced in .NET 3.0. in the System.ServiceModel namespace. WCF is based on basic concepts of Service oriented architecture (SOA)

What is endpoint in WCF service?

The endpoint is an Interface which defines how a client will communicate with the service. It consists of three main points: Address, Binding and Contract.

Explain Address,Binding and contract for a WCF Service?

Address:Address defines where the service resides.
Binding:Binding defines how to communicate with the service.
Contract:Contract defines what is done by the service.

What are the various address format in WCF?

a)HTTP Address Format:--> http://localhost:
b)TCP Address Format:--> net.tcp://localhost:
c)MSMQ Address Format:--> net.msmq://localhost:


What are the types of contract available in WCF?

The main contracts are:
a)Service Contract:Describes what operations the client can perform.
b)Operation Contract : defines the method inside Interface of Service.
c)Data Contract:Defines what data types are passed
d)Message Contract:Defines wheather a service can interact directly with messages


What are the various ways of hosting a WCF Service?

a)IIS b)Self Hosting c)WAS (Windows Activation Service)

What is the proxy for WCF Service?

A proxy is a class by which a service client can Interact with the service.
By the use of proxy in the client application we are able to call the different methods exposed by the service

How can we create Proxy for the WCF Service?

We can create proxy using the tool svcutil.exe after creating the service.
We can use the following command at command line.
svcutil.exe *.wsdl *.xsd /language:C# /out:SampleProxy.cs /config:app.config

What is the difference between WCF Service and Web Service?

A) WCF Service supports both http and tcp protocol while webservice supports only http protocol.
b) WCF Service is more flexible than web service.





1). what is Address Header in WCF?

Address Header contains the information which is sent with every request, it can be used by either end point service or any intermediate device for determining any routing logic or processing logic.
WCF provides Address Header class for this purpose.
AddressHeader addressHeader= AddressHeader.CreateAddressHeader ("Name header", "Information in header ");

2).In WCF which bindings support the reliable session?

In WCF, following bindings supports the reliable session
1. WsHttpBinding
2. WsDualHttpBinding
3. WsFederationHttpBinding
4. NetTcpBinding
// Code for IService Class
// NOTE: If you change the interface name "IService" here, you must also update the reference to "IService" in Web.config.
[ServiceContract]
public interface IService
{

[OperationContract]
string GetData(int value);

[OperationContract]
CompositeType GetDataUsingDataContract(CompositeType composite);

// TODO: Add your service operations here
}

// Use a data contract as illustrated in the sample below to add composite types to service operations.
[DataContract]
public class CompositeType
{
bool boolValue = true;
string stringValue = "Hello ";

[DataMember]
public bool BoolValue
{
get { return boolValue; }
set { boolValue = value; }
}

[DataMember]
public string StringValue
{
get { return stringValue; }
set { stringValue = value; }
}
}


//Code for Service Class
// NOTE: If you change the class name "Service" here, you must also update the reference to "Service" in Web.config and in the associated .svc file.
public class Service : IService
{
public string GetData(int value)
{
return string.Format("You entered: {0}", value);
}

public CompositeType GetDataUsingDataContract(CompositeType composite)
{
if (composite.BoolValue)
{
composite.StringValue += "Suffix";
}
return composite;
}
}

//Code of webConfig






















Wednesday, December 1, 2010

Creating pdf From single Tiff image with itextSharp

//This is the program explain to us that how to create a pdf file form a tiff image


using iTextSharp.text;
using iTextSharp.text.pdf;


private void ImageToPdfConverter(string ImageP, string pdfP)
    {
        //FileStream fs = File.Open(@"D:\Tiff.pdf", FileMode.Create, FileAccess.Write);
        string ImagePath = ImageP;// Server.MapPath("image/");
        string PdfPath = pdfP;// Server.MapPath("pdf");
        //PdfPath = "D:/";
        //ImagePath = @"D:\Crop\01\163011410.tif";
        Document doc = new Document();
        PdfWriter.GetInstance(doc, new FileStream(PdfPath, FileMode.Create));
        doc.Open();
        // doc.Add(new Paragraph("TIF Scaled to 300dpi"));
        iTextSharp.text.Image tif = iTextSharp.text.Image.GetInstance(ImagePath );
        tif.ScalePercent(24f);
        tif.ScaleToFit(doc.PageSize.Width - 50, doc.PageSize.Height - 50);
        doc.Add(tif);
        doc.Close();


    }

Thursday, November 25, 2010

how Generate pdf to other pdf

//This code is user to generate or create a copy of one pdf to other pdf. 




using iTextSharp.text;
using iTextSharp.text.pdf;
Private void GetPdf()
{


 int pageNumber = 1;
        strURL = txtUrl.Text.Trim(); // URL like http://..../my.pdf
        PdfReader reader = new PdfReader(strURL);
       
        Rectangle size = reader.GetPageSizeWithRotation(pageNumber);
        Document document = new Document(size);
        PdfWriter writer = PdfWriter.GetInstance(document, new FileStream(@"D:\Development\NASearcg\LogRuntime.pdf", FileMode.Create, FileAccess.Write));


        //set document info
        document.AddTitle("Document copied using iTextSharp");
        document.AddAuthor("Joachim Tesznar");
        document.AddSubject("Dynamic Content");
        document.AddCreator("PDF Form Tool by Joachim Tesznar");


        document.Open();


        PdfContentByte cb = writer.DirectContent;
        document.NewPage();
        PdfImportedPage page = writer.GetImportedPage(reader, pageNumber);
        cb.AddTemplate(page, 0, 0);
        document.Close();



}

Thursday, November 18, 2010

Code for Geting the client Ip Address

1) First Way to get the client Ip Address in asp.net with C#
string ip;

ip = Request.ServerVariables["HTTP_X_FORWARDED_FOR"];
        if (!string.IsNullOrEmpty(ip))
        {
           string[] ipRange = ip.Split(',');
           int le = ipRange.Length - 1;
            string trueIP = ipRange[le];
        }
        else
        {
            ip = Request.ServerVariables["REMOTE_ADDR"];
        }
       Response.Write(ip);
        Response.Write(Request.UserHostAddress);


2)Second Way to Get the client up address in asp.net with C#


        string strHostName = System.Net.Dns.GetHostName();
        string clientIPAddress = System.Net.Dns.GetHostAddresses(strHostName).GetValue(0).ToString();
        Response.Write(clientIPAddress);

Tuesday, October 12, 2010

WCF Tutorials

http://www.techbubbles.com/net-framework/wcf-sample-in-visual-studio-2008/

Tuesday, October 5, 2010

how to insert an identity value explicitly into a identity column in SqlServer

Step 1:- Set the IDENTITY_INSERT property for the desire table as On


Step 2:- Perform your insert operation


Step 3:- Set the IDENTITY_INSERT property for that particular table as off


Example are as folllows:-



SET IDENTITY_INSERT IdentityTable ON

INSERT IdentityTable(TheIdentity, TheValue)
VALUES (3, 'First Row')

SET IDENTITY_INSERT IdentityTable OFF

Friday, September 3, 2010

How to remove the cache of the page

//This code is use to remove the cache of the 
//page put this code on the page load
//inside the !ispostback than it will clear 
//all the cache of the page before loading. 
 
 
Response.Cache.SetCacheability(HttpCacheability.NoCache);

Wednesday, August 18, 2010

Genrating a PDF from HTML using itextsharp

public void GenratePdfFromString()
    {
   
    string str ="
MY Name is PraveenAll the guys
";

        Document ObjDocument = new Document();
        StringWriter sw = new StringWriter();
        HtmlTextWriter hw = new HtmlTextWriter(sw);
        StringReader sr = new StringReader(str);

        iTextSharp.text.html.simpleparser.HTMLWorker htmlParser = new iTextSharp.text.html.simpleparser.HTMLWorker(ObjDocument);
        PdfWriter.GetInstance(ObjDocument, new FileStream(Server.MapPath("Chapter01.pdf"), FileMode.Create));
        ObjDocument.Open();       
        htmlParser.Parse(sr);
        ObjDocument.Close();

        Response.Write("Converted");
   
   
    }

Tuesday, June 1, 2010

Tool for Test the Wcf Service

Go to the open the visual studio command prompt and type the following command

C:\Program Files\Microsoft Visual Studio 9.0\Common7\IDE\wcfTestClient.exe [Wcf Service URL]

Like
C:\Program Files\Microsoft Visual Studio 9.0\Common7\IDE\wcfTestClient.exe http://localhost/myservice/service1.svc

and press Enter the see the result

Friday, May 7, 2010

Code For ThambnailImage from a image in asp.net and C#

// ThumbNail Region
///
/// This function used for setting the size of image at run time
///
///
///
public void AutoImageSize(string orgpath, string modpath, int size)
{
//int maxDimension = 153;//this value can be any thing......
int maxDimension = size;
Bitmap bm = new Bitmap(orgpath);
double num = ((float)bm.Width) / ((float)bm.Height);
if (System.IO.File.Exists(modpath))
{
System.IO.File.Delete(modpath);
}
if ((num > 1.0) && (bm.Width > maxDimension))
{

System.Drawing.Image image = new Bitmap(maxDimension, (int)(((double)maxDimension) / num));
Graphics graphics = Graphics.FromImage(image);
graphics.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
graphics.DrawImage(bm, 0, 0, maxDimension, (int)(((double)maxDimension) / num));
image.Save(modpath);
image.Dispose();
}
else if (bm.Height > maxDimension)
{
System.Drawing.Image image = new Bitmap((int)(maxDimension * num), maxDimension);
Graphics graphics = Graphics.FromImage(image);
graphics.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
graphics.DrawImage(bm, 0, 0, (int)(maxDimension * num), maxDimension);
image.Save(modpath);
image.Dispose();
}
else
{
System.Drawing.Image image = new Bitmap(bm);
image.Save(modpath);
image.Dispose();
}

bm.Dispose();
}

//How to Call
//comobj.AutoImageSize(Request.PhysicalApplicationPath + "Admin/Places/Actual/" + //objImageName.ToString(), Request.PhysicalApplicationPath + "Admin/Places/Actual/" + //"_UploadPlaceImg" + imgcnt + objImageName.ToString(), 120);

LINQ to SQL: returning multiple result sets

//How to get the multiple table in LINQ Instead of dataset(If procedure returns more than one //table)

http://blogs.msdn.com/swiss_dpe_team/archive/2008/02/04/linq-to-sql-returning-multiple-result-sets.aspx

Friday, January 22, 2010

JavaScript validateion for blank space

function CheckSpace(c)
{


var val=c;
var str;
for(var i=0;i<=val.length-1;i++)
{
if(val.charAt(i)==' ')
{
str=true;
}
else
{
str=false;
break;
}
}
return str
}

//Method to call this function

var val = document.getElementById('<%=txtDescription.ClientID %>').value;
if(CheckSpace(val))
{
alert('Space is not allowed');
return false;
}

Thursday, January 21, 2010

Sql query for select the rendom record in sqlserver

SELECT TOP 1 * FROM TBL_PERDETAILS ORDER BY NEWID()

//HERE NEWID() FUNCTION WILL GENRATE THE RENDOM ID

Tuesday, January 19, 2010

How to Get the value and text of a Dropdownlist using JavaScript

//Using this function you can get the value and text of dropdownList using JavaScript

function GetDropDornListValueAndText()
{
ddlReport = document.getElementById("<%=DropDownListReports.ClientID%>");
var Text = ddlReport.options[ddlReport.selectedIndex].text;
var Value = ddlReport.options[ddlReport.selectedIndex].value;

}