Microsoft.NET framework 3.0 had new features called WCFServiceLibrary template through this you can create the dll for your service.Mostly this will be best option of making business logic for WCF Services.
In this post,I am going to explain how to create the WCFService Libray,how to utilise them in WCFService and then consuming the services.
Step 1
Select the template name "WCFServiceLibrary" and choose the .NET framwork 3.0 as above.
Step 2
Here I just created the function name GetDataLength.This will returns the number of characters in the passing string.
Before I removed the by default text from the source file.
Step 3
An implementation of the function GetDataLength will be
Step 4
After completion of compile,you can see the dll file on your project stored location.
This will be the source for your WCF service.
Step 5
Now open second visual studio 2008 window,and choose the classing WCF Service,here you are going to use the just created WCFServiceLibrary as source.
Step 6
In your WCFService application use AddReference to include the WCFServiceLibrary's dll as below
Step 7
In your code behind,I created the WCFService method name GetDataFromLibrary,this will takes the string as parameter,and then its length will be processed by the WCFServiceLibrary and sent back to your WCFService.
Step -8
Code Implementation for the above method.
Step 9
After this run the application to create the .svc file for generating proxy class for your consumer application.
Step 10
Create the proxy class using svcutil.exe
Step 11
Add the proxy class into your website application in order to consume the WCFService that use the WCFServiceLibrary dll.And place the text box and button for checking the user input's length.
Step 12
You must copy have the endpoint details in your web.config file.Check the output.xml on your generated proxy class location.Pick the servicemodel tag and upto endof servicemodel tag as belows
On your Button click event,Just follow the same code snippet for getting the result from the WCFService.
The result I have got,
Saturday, December 20, 2008
Friday, December 05, 2008
Merging the array values
Before writing the actual code I tested this arrays to calculate has to be done on one array and another will be as it is.
double[] Pre = new double[3];
Pre[0] = 1;
Pre[1] = 2;
Pre[2] = 3;
double[] Pre1 = new double[3];
Pre1[0] = 4;
Pre1[1] = 5;
Pre1[2] = 6;
string n1 = "";
string n2 = "";
for (int i = 0; i < Pre.Length; i++)
{
n1 = n1 + "-" + Pre[i].ToString() + ",";
}
for (int a = 0; a < Pre1.Length; a++)
{
n2 = n2 + Pre1[a].ToString() + ",";
}
string result = n1 + n2.TrimEnd(',');
Response.Write(result.ToString());
double[] Pre = new double[3];
Pre[0] = 1;
Pre[1] = 2;
Pre[2] = 3;
double[] Pre1 = new double[3];
Pre1[0] = 4;
Pre1[1] = 5;
Pre1[2] = 6;
string n1 = "";
string n2 = "";
for (int i = 0; i < Pre.Length; i++)
{
n1 = n1 + "-" + Pre[i].ToString() + ",";
}
for (int a = 0; a < Pre1.Length; a++)
{
n2 = n2 + Pre1[a].ToString() + ",";
}
string result = n1 + n2.TrimEnd(',');
Response.Write(result.ToString());
Wednesday, December 03, 2008
Loding multiple tables in DataSet
How to load multiple tables in DataSet programmatically ?
DataSet ds= new DataSet();
string strConn="Server=(local);dataBase=Northwind;user id=sa;password=;";
SqlConnection cn = new SqlConnection(strConn);
string strSQL="select * from Customers;select * from employees";
cn.Open();
SqlDataAdapter da = new SqlDataAdapter( strSQL,cn);
ds.Tables.Add("Customers");
ds.Tables.Add("Employees");
ds.EnforceConstraints =false;
ds.Tables["Customers"].BeginLoadData();
da.Fill(ds.Tables["Customers"]);
ds.Tables["Customers"].EndLoadData();
ds.Tables["Employees"].BeginLoadData();
da.Fill(ds.Tables["Employees"]);
ds.Tables["Employees"].EndLoadData();
dataGrid1.DataSource=ds.Tables["Customers"];
dataGrid2.DataSource=ds.Tables["Employees"];
cn.Close();
DataSet ds= new DataSet();
string strConn="Server=(local);dataBase=Northwind;user id=sa;password=;";
SqlConnection cn = new SqlConnection(strConn);
string strSQL="select * from Customers;select * from employees";
cn.Open();
SqlDataAdapter da = new SqlDataAdapter( strSQL,cn);
ds.Tables.Add("Customers");
ds.Tables.Add("Employees");
ds.EnforceConstraints =false;
ds.Tables["Customers"].BeginLoadData();
da.Fill(ds.Tables["Customers"]);
ds.Tables["Customers"].EndLoadData();
ds.Tables["Employees"].BeginLoadData();
da.Fill(ds.Tables["Employees"]);
ds.Tables["Employees"].EndLoadData();
dataGrid1.DataSource=ds.Tables["Customers"];
dataGrid2.DataSource=ds.Tables["Employees"];
cn.Close();
Subscribe to:
Posts (Atom)