Thursday, July 29, 2010
WCF Client Sample code
{
using (WCFServiceClient client = new WCFServiceClient("WSDualHttpBinding_IWCFService"))
{
string output = client.MyOperation1("Manoj");
Console.WriteLine(output);
DataContract1 dc = new DataContract1();
dc.FirstName = "Shankar";
dc.LastName = "Mahadevan";
output = client.MyOperation2(dc);
Console.WriteLine(output);
Console.ReadLine();
}
Configuration of WCF in Host
[OperationContract]
[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
< 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
Wednesday, May 5, 2010
SQL Server built in functions
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;
GO
Wednesday, April 7, 2010
Design patterns
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.
Source Web Form
Add following properties to the web form:public string Name { get { return TextBox1.Text; } } public string EMail { get { return TextBox2.Text; } }Now, call Server.Transfer.
private void Button1_Click (object sender, System.EventArgs e) { Server.Transfer("anotherwebform.aspx"); }
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 wf1=(WebForm1)Context.Handler; Label1.Text=wf1.Name; Label2.Text=wf1.EMail; }
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.
[DataContract]
public class MyFaultException
{
private string _reason;
[DataMember]
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
- While in the Package designer, choose Project > [Package Name] Properties. The Configuration manager dialog will appear.
- Choose Deployment Utility from the tree.
- Change the CreateDeploymentUtility option from False to True. Note the DeploymentOutputPath variable. Push OK to close the dialog.
- 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.
- 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
- Open MSFT SQL Server Management Studio and choose Connect > Integration Services from the UI. Choose the Server and connect.
- 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
<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>