Thursday, July 29, 2010

WCF Client Sample code

static void Main(string[] args)
using (WCFServiceClient client = new WCFServiceClient("WSDualHttpBinding_IWCFService"))
string output = client.MyOperation1("Manoj");
DataContract1 dc = new DataContract1();
dc.FirstName = "Shankar";
dc.LastName = "Mahadevan";
output = client.MyOperation2(dc);

Configuration of WCF in Host

[System.ServiceModel.Web.WebGet(UriTemplate = "/MyOperation/MyOperation1/{myValue1}", ResponseFormat = System.ServiceModel.Web.WebMessageFormat.Json, BodyStyle = System.ServiceModel.Web.WebMessageBodyStyle.WrappedResponse)]

[ServiceBehavior(InstanceContextMode = InstanceContextMode.PerCall, IncludeExceptionDetailInFaults = true)]

[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Required)]

Generating a proxy for the client
svcutil.exe /language:cs /out:generatedProxy.cs /config:app.config http://localhost:2409/WCF_Host/Service.svc

Configuration of webHttpBinding and wsDualHttpBinding

< ?xml version="1.0"?>
< configuration>
< system.serviceModel>
< serviceHostingEnvironment aspNetCompatibilityEnabled="true" />
< behaviors>
< endpointBehaviors>
< behavior name="webHttpEnablingBehavior">
< webHttp />
< /behavior>
< /endpointBehaviors>
< serviceBehaviors>
< behavior name="webHttpEnablingBehavior">
< serviceMetadata httpGetEnabled="true"/>
< serviceDebug includeExceptionDetailInFaults="true" />
< /behavior>
< /serviceBehaviors>
< /behaviors>
< services>
< service name="WCFService" behaviorConfiguration="webHttpEnablingBehavior">
< endpoint contract="IMetadataExchange" binding="mexHttpBinding" address="mex" />
< endpoint address="" binding="webHttpBinding" bindingConfiguration="default" contract="IWCFService" behaviorConfiguration="webHttpEnablingBehavior" />
< endpoint address="MyOperation" binding="wsDualHttpBinding" bindingConfiguration="default" contract="IWCFService" />
< /service>
< /services>
< client />
< bindings>
< webHttpBinding>
< binding name="default" />
< /webHttpBinding>
< wsDualHttpBinding>
< binding name="default" />
< /wsDualHttpBinding>
< /bindings>
< /system.serviceModel>
< system.web>
< compilation debug="true"/>
< /system.web>
< /configuration>

Monday, May 24, 2010

Using CSS with Inline Images

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <html xmlns=""> <head> <style type="text/css"> .clip { position: absolute; top: 0; left: 0; } .pos-1 { clip:rect(0 48px 48px 0); } .pos-2 { clip:rect(0 96px 48px 48px); left: -48px; } .pos-3 { clip:rect(48px 48px 96px 0); top: -48px; } .pos-4 { clip:rect(48px 96px 96px 48px); top: -48px;left: -48px; } .clipwrapper { position: relative; height: 48px; width: 48px; } </style> <title></title> </head> <body> <div class="clipwrapper"> <img src="Images/arrow-sprite.png" alt="arrow" class="clip pos-1" /> </div> </body> </html>

Wednesday, May 5, 2010

SQL Server built in functions

1. First day of the week
select @@DateFirst output: 7 - Monday , 1 - Sunday
Set dateFirst 1
To see the permissions in the database.
select * from fn_my_permissions('null','database')
SELECT DISTINCT class_desc FROM fn_builtin_permissions(default) ORDER BY class_desc;

Wednesday, April 7, 2010

Design patterns

One way is to call carpenter and let him take the measurements and then get you the door. --- factory method
Second way is to go to shop which sells doors and get the one which fits your requirements. --- abstract factory
Tracking a Session counter creates a single object - Singleton pattern

Wednesday, March 24, 2010

Using Server.Transfer

This is somewhat complex but sophisticated method of passing values  across pages. Here you expose the values you want to access in other  pages as  properties of the page class. This methods require you to code extra  properties that you can access in another web form. However, the efforts  are worth considering. Overall this method is much cleaner and object  oriented than earlier methods. The entire process works as follows:
  • Create the web form with controls
  • Create property Get procedures that will return control values
  • Provide some button or link button that posts the form back
  • In the button click event handler call Server.Transfer method that will transfer execution to the specified form
  • In the second form you can get a reference to the first form instance by using Context.Handler property. Then you will use the get properties we created to access the control values.
The code to accomplish this is somewhat complex and is shown below:
Source Web Form
Add following properties to the web form:
public string Name
return TextBox1.Text;

public string EMail
return TextBox2.Text;
Now, call Server.Transfer.
private void Button1_Click
(object sender, System.EventArgs e)
Destination Web Form
private void Page_Load
(object sender, System.EventArgs e)
//create instance of source web form
WebForm1 wf1;
//get reference to current handler instance

Fault Exception in WCF

calling the FaultException in Catch block

catch (Exception ex)


throw ex ;

// useful when FaultException attribute is mentioned in the web method called.

//with method declaration in interface.

////[FaultContract(typeof (MyFaultException))]

//MyFaultException myException = new MyFaultException();

//myException.Reason = "Reason for this error is : " + ex.Message.ToString();


Fault exception definition

// optional but a good practice.


public class MyFaultException


private string _reason;


public string Reason


get { return _reason; }

set { _reason = value; }



Thursday, March 18, 2010

How to Deploy and Test An SSIS Package

When working with SSIS, it is not immediately obvious how to deploy a package. Following are my short notes on deploying an SSIS package*.

Deploy the Package

  1. While in the Package designer, choose Project > [Package Name] Properties. The Configuration manager dialog will appear.
  2. Choose Deployment Utility from the tree.
  3. Change the CreateDeploymentUtility option from False to True. Note the DeploymentOutputPath variable. Push OK to close the dialog.
  4. Open the Solution Explorer and right-click on the .dtsx file and choose Properties. Copy the Full Path variable and use it to find the bin\Deployment folder.
  5. Locate the [Package Name].SSISDeploymentManifest file. Double-click on the file and follow the steps outlined by the wizard to deploy the package.

Test the deployed Package

  1. Open MSFT SQL Server Management Studio and choose Connect > Integration Services from the UI. Choose the Server and connect.
  2. The packages will be saved under the MSDB folder. Right-click on the package to run it.


* To re-deploy a package, follow steps 1-5 again.

Assigning a value to an ASP.Net CheckBox

Unlike the html checkbox, the ASP.Net CheckBox control does not have a value property. However, you can add attributes via markup as well as pragmatically via code. Markup:
<asp:checkbox id="CheckBox1" runat="server" value="'<%# Eval(" valuecolumn="">' /> <asp:checkbox id="CheckBox2" runat="server" value="'2'">
Only Eval can be used to bind to "custom" attributes, as compared to properties built into the control which also work with Bind Code:
CheckBox2.Attributes.Add("Value", 2);
The "Add" method add takes two parameters. The first parameter is the name of the attribute . The second parameter is the value for this attribute. This adds a server accessible attribute for the value, the attributes collection is maintained via the viewstate. However the CheckBox control does not render the value attributed (it actually removes the attribute during the render event phase. However, if you want to add the attribute so it is rendered via html then the checkbox has a property called InputAttributes, adding properties to this collection will always be rendered in the html. Code: CheckBox2.InputAttributes.Add("Value", 2);</asp:checkbox></asp:checkbox>

ASP.Net Trace stops showing up

I've noticed that when using 2.0 dev server that the trace would only show up on one or two pages. I decided to do some research into it and found out it has to do with the trace section of webconfig. There is a attribute called requestLimit whose limit was set to 20. After 20 requests the trace just stops showing up. 20 requests may not sound that bad but with the dev server all requests (including images and everything) go through the runtime so one page with my website would have 20 requests for other resources. I found out that there is another attribute called mostRecent which when set to true will discard older requests rather than stop working. I also didn't read the note in the webconfig about "you can view the application trace log by browsing the "trace.axd" page from your web application root".

Tuesday, February 16, 2010

Getting columns name from a table in Sql Server

SELECT FROM sysobjects, syscolumns WHERE = and'Profile'