Thursday, June 25, 2009

WCF concepts

WCF concepts include ABC i.e,

A - Address
B - Binding
C – Contract
Services are building on windows communication foundation’s System.ServiceModel assembly in location


C:\Windows\Microsoft.NET\Framework\v3.0\Windows Communication Foundation.

I found some useful resources from MSDN when i searched the web.


You'll get samples from MSDN, Download Samples


MSDN Tutorial for WCF,

How to: Define a Windows Communication Foundation Service Contract
How to: Implement a Windows Communication Foundation Service Contract
How to: Host and Run a Basic Windows Communication Foundation Service
How to: Create a Windows Communication Foundation Client
How to: Configure a Basic Windows Communication Foundation Client
How to: Use a Windows Communication Foundation Client

Monday, June 22, 2009

Creating the Web Service Proxy using wsdl

Creating the Web Service Proxy

A client and a Web service can communicate using SOAP messages, which encapsulate the input and output parameters as XML. A proxy class maps parameters to XML elements and then sends the SOAP messages over a network. In this way, the proxy class frees you from having to communicate with the Web service at the SOAP level and allows you to invoke Web service methods in any development environment that supports SOAP and Web service proxies.

There are two ways to add a proxy class to your development project using the Microsoft .NET Framework: with the WSDL tool in the .NET Framework, and by adding a Web reference in Microsoft Visual Studio. The following sections discuss this subject in further detail.

Adding the Proxy Using the WSDL Tool
The .NET Framework SDK includes the Web Services Description Language tool (Wsdl.exe), which enables you to generate a Web service proxy for use in the.NET Framework development environment. The most common way to create a client proxy in languages that support Web services (currently C# and Microsoft Visual Basic) is to use the WSDL tool.

To add a proxy class to your project using Wsdl.exe

From a command prompt, use Wsdl.exe to create a proxy class, specifying (at a minimum) the URL to the Report Server Web service.
For example, the following command prompt statement specifies a URL for the management endpoint of the Report Server Web service:
Copy Code
wsdl /language:CS /n:"Microsoft.SqlServer.ReportingServices2005" http://myserver/reportserver/reportservice2005.asmx?wsdl
The WSDL tool accepts a number of command-prompt arguments for generating a proxy. The preceding example specifies the language C#, a suggested namespace to use in the proxy (to prevent name collision if using more than one Web service endpoint), and generates a C# file called ReportingService2005.cs. If the example had specified Visual Basic, the example would have generated a proxy file with the name ReportingService2005.vb. This file is created in the directory from which you run the command.

Compile the proxy class into an assembly file (with the extension .dll) and reference it in your project, or add the class as a project item.
Note:
When you add a proxy class to your project manually, you need to add a reference to System.Web.Services.dll. If you add the proxy using a Web reference in Visual Studio .NET, the reference is automatically created for you. For more information, see "Adding the Proxy Using a Web Reference in Visual Studio" later in this topic.

Friday, June 19, 2009

Creating Proxy Class with Visual Studio .NET 2005

Creating Proxy Class with Visual Studio .NET 2005
Visual Studio .NET 2005 provides the capability to create class files that contain the proxy code utilized to access the web services. The WSDL tool is used to generate proxy code from WSDL files. The generated class is used to instantiate objects for communicating with the Web services via SOAP messages.

Creating Proxy Class in C#
1) From within your Visual Studio 2005 folder in your start menu, select "Visual Studio Tools"

2) Within the "Visual Studio Tools" menu select "Visual Studio 2005 Command Prompt".

Note
This shortcut automatically loads up all of the environment variables needed to access special tools in Visual Studio .Net without having to specially modify the operating system variables.

3) Within the command prompt, change the directory to the directory of your application.

Note
If you do not change your directory, the default location for your file will be:


C:\Program Files\Microsoft Visual Studio 8\VC
4) Within the command prompt window, type the following command:


wsdl http://jlab.calumet.purdue.edu/thegateway/v2/0/pathwaygateway.asmx?wsdl
Note The filename "GatewayPathway.CS" will be in the location you specified in step 3.

5) Within your Visual Studio 2005 project, open Solution Explorer.

6) Within the Solution Explorer right click on the project name and select "Add Existing Item..." and the "Add Existing Item" dialog box will appear


7) Within the "Add Existing Item" dialog box, browse to the location of your file if not in the project folder, and select the file "PathwayGateway.cs" you created in step 4.

Note
The File has now been added to your project and will be listed in your Solution Explorer.

Creating Proxy Class in VB.NET
1) From within your Visual Studio 2005 folder in your start menu, select "Visual Studio Tools"

2) Within the "Visual Studio Tools" menu select "Visual Studio 2005 Command Prompt".

Note
This shortcut automatically loads up all of the environment variables needed to access special tools in Visual Studio .Net without having to specially modify the operating system variables.

3) Within the command prompt, change the directory to the directory of your application.

Note
If you do not change your directory, the default location for your file will be:

C:\Program Files\Microsoft Visual Studio 8\VC
4) Within the command prompt window, type the following command:


wsdl http://jlab.calumet.purdue.edu/thegateway/v2/0/pathwaygateway.asmx?wsdl /language:VB
Note The filename "GatewayPathway.vb" will be in the location you specified in step 3.

5) Within your Visual Studio 2005 project, open Solution Explorer.

6) Within the Solution Explorer right click on the project name and select "Add Existing Item..." and the "Add Existing Item" dialog box will appear


7) Within the "Add Existing Item" dialog box, browse to the location of your file if not in the project folder, and select the file "PathwayGateway.VB you created in step 4.

Note
The File has now been added to your project and will be listed in your Solution Explorer.

Wednesday, June 17, 2009

Using repeater control

I store the menu categories in a table called "Sub_Category" in SQL Server, so that if I ever need to add one, I just add it to the table and it will appear on the menu. There are two fields in the table: Sub_Category_ID, and Sub_Category_Text.
Step 1 - Create the Page and Insert the Repeater Control
The Repeater control allows you to create templates to define the layout of its content. The templates are:
ItemTemplate - Use this template for elements that are rendered once per row of data.
AlternatingItemTemplate - Use this template for elements that are rendered every other row of data. This allows you to alternate background colors, for example.
HeaderTemplate - Use this template for elements that you want to render once before your ItemTemplate section.
FooterTemplate - Use this template for elements that you want to render once after your ItemTemplate section.
SeperatorTemplate - Use this template for elements to render between each row, such as line breaks.
Here is a part of the Web Form (subcategories.aspx) that contains the Repeater:
.... jpg" width="91" height="28" class="bigtext">
" Text="<%#DataBinder.Eval(Container.DataItem, "Sub_Category_Text")%>" runat="server" target="mainFrame" ID="Hyperlink1" NAME="Hyperlink1"/>
....
The Repeater has a name of "catlist". It uses the HeaderTemplate to print out the Areas image. It then uses the ItemTemplate to display a Hyperlink control that has our data in it. We'll come back to this in Step Two.
The FooterTemplate is not necessary, but I put it in here for consistency.
Step 2 - Get the Data
Now let's look at the data retrieval. Here is the Page_Load event in the Code Behind file.
private void Page_Load(object sender, System.EventArgs e) { SqlConnection conDotNet = new SqlConnection "Server=xxxxxxx;UID=xxxx;PWD=xxxxx;Database=DotNetGenius"); string sSQL = "Select sub_category_id, sub_category_text from Sub_Category"; SqlCommand cmd = new SqlCommand(sSQL, conDotNet); conDotNet.Open(); SqlDataReader dtrCat = cmd.ExecuteReader(); catlist.DataSource = dtrCat; catlist.DataBind(); }
The first five lines open a database connection and retrieve the contents of the Sub_Category table. The last two lines bind our Repeater control to the DataReader. Now, let's look again at the ItemTemplate section:
" Text="<%#DataBinder.Eval(Container.DataItem, "Sub_Category_Text")%>" runat="server" target="mainFrame" ID="Hyperlink1" NAME="Hyperlink1"/>

Once the DataBind method of the Repeater control is called, ASP.NET will loop through the DataReader and populate the Repeater with the data we specify. The Databinder.Eval method uses reflection to parse and evaluate a data-binding expression against an object at run time, in this case the object is our Repeater. So this line of code:
NavigateUrl="<%# "mainframeset.aspx?CatType=" + DataBinder.Eval(Container.DataItem,"Sub_Category_ID")%>"
will render the contents of the "Sub_Category_ID" field for each row in the DataReader.
If you spend much time with ASP.NET, you will certainly be using this control often. I hope you find it handy!