Saturday, June 20, 2009

Converting DataSet to array list

public string[] ProductList()
{

ArrayList al = new ArrayList();
string s = "";

Database db = DatabaseFactory.CreateDatabase();
DbCommand cmd = db.GetSqlStringCommand("SELECT ProductName from Products");
DataSet ds = db.ExecuteDataSet(cmd);

foreach (DataRow dRow in ds.Tables[0].Rows)
{

al.Add(dRow);
}

foreach (Object row in al)
{
s = s + ((DataRow)row)["ProductName"].ToString() + ",";

}
string rawString = s.TrimEnd(',').ToString();
string[] result = rawString.Split(',');
return result;

}
then you can bind this array to Gridview
Gridview1.DataSource=ProductList();
Gridview1.Bind();

Tuesday, June 16, 2009

MSMQ - Architecture

This will be the simplest understanding diagram of what MSMQ architecture is
********************************************************
Sending Application[Physical]
|
|
|
V
MSMQ [Layer built in topof SQL Server]
|
|
|
V
Receiving Application [Physical]

**********************************************

Sending Application
|
|
|------>Writes Message [Transaction - 1]
|
|
|
|------> Put written message into Queue [Transaction-2]


Sending application prepares a message and puts into Queue.
A Message can be any type of information that receiving application understand.
Receiving Application
Receives the messages and process them.
Notes:
Receiving application and Sending application were not tightly coupled,they can work
without help of other application support

How it was possible ?
Because of built-in layers between connected computers[clients].
Two types of Messages are there,one is Private Message and secondly we have Public
message
Private message :These messages only on locally on particular machine and are not
published on publically.
Public message: These messages will reside on active directory.So applications
running on different servers throughout the network can find the public queues
through active directory.

Monday, June 15, 2009

Exception handling in WCF

This is an simple example for how to manage exception in WCF and their client.
WCF returns system exception and application exception during development time.
But hosting time,these kind of exception will not handled by SOAP protocol.
So SOAP friendly exception details must be implemented on service side using FaultContractAttribute.
Generate the custome exception message must be implemented on a class that start preceding with DataContractAttribute.

WCF Source for Exception handling

[ServiceContract]
public interface IService
{
[OperationContract]
[FaultContractAttribute(typeof(FaultContractExceptionTest))]
string GetData(int value);

}
[DataContractAttribute]
public class FaultContractExceptionTest
{
private string Msg;
public FaultContractExceptionTest(string msg)
{
this.Msg = msg;
}
[DataMember]
public string ErrorMessage
{
get { return this.Msg; }
set { this.Msg = value; }
}
}
________________________________________________________________________

Service Implementation Source
_________________________________________________________________________
public class Service : IService
{
public string GetData(int value)
{

if (value == 152)
{
return "Your authentication code is " + value.ToString();
}
else
{
throw new FaultException(new FaultContractExceptionTest("Check your Pass Number"),"Some Problem");
}}}


Client Implementation - Source code - I written on Button click event
ServiceClient sc = new ServiceClient();
try
{

Response.Write(sc.GetData(Convert.ToInt32(TextBox1.Text)));

}

catch (FaultException msgObj)
{
Response.Write(msgObj.Detail.ErrorMessage);
}