<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Three2Tango &#187; ASP.Net</title>
	<atom:link href="http://www.three2tango.com/category/techcorner/aspnet/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.three2tango.com</link>
	<description>Points To Ponder : The Latest news from the TechWorld,Automobiles,CellPhones and lots of useful Code Snippets</description>
	<lastBuildDate>Fri, 27 Jan 2012 09:03:17 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Create a web service client from wsdl in .Net</title>
		<link>http://www.three2tango.com/techcorner/create-a-web-service-client-from-wsdl-in-net.html/</link>
		<comments>http://www.three2tango.com/techcorner/create-a-web-service-client-from-wsdl-in-net.html/#comments</comments>
		<pubDate>Fri, 14 Jan 2011 14:54:08 +0000</pubDate>
		<dc:creator>Vivek</dc:creator>
				<category><![CDATA[ASP.Net]]></category>
		<category><![CDATA[Tech Corner]]></category>
		<category><![CDATA[.net web service client]]></category>
		<category><![CDATA[.NET Web Services]]></category>

		<guid isPermaLink="false">http://www.three2tango.com/?p=4279</guid>
		<description><![CDATA[The wsdl (Web service description language) provides a model for describing the web service. We can build applications that consume the web service using just the wsdl. Creating a web service client to consume a web service with wsdl is relatively very easy compared to creating one in Java or any other language. It is worth remembering that a web service could be coded in any language and an application that consumes the web service can be in another language. For Example: My web service may be written in Java ...]]></description>
			<content:encoded><![CDATA[<p>The wsdl (Web service description language) provides a model for describing the web service. We can build applications that consume the web service using just the wsdl. Creating a web service client to consume a web service with wsdl is relatively very easy compared to creating one in Java or any other language. It is worth remembering that a web service could be coded in any language and an application that consumes the web service can be in another language. For Example: My web service may be written in Java and I can make a client application in .Net that uses the web services. In short, web services have a platform/language independent nature.</p>
<p>Now to create a .Net client to consume a web service, first step is to add the wsdl as reference. In Visual Studio, right click the project folder in Solution explorer and select “Add Web Reference”. </p>
<p>In the URL field, provide the URL of the wsdl. If any authentication is to be provided to access the web service, the system will prompt you to enter the credentials also. Click on “Add Reference” button after filling in the web reference name. Once you have added the reference, it will appear under the App_webReferences folder in solution explorer (VS2008).</p>
<p>Now that we have added the web reference, next step is to create an object of the web service. First add the namespace and then create an object to access the web service methods. Eg: If the reference name added was “example”, then the object should be created as:</p>
<p>   Example client = new Example ();</p>
<p> </p>
<p>Once the object is created, accessing the methods of the web service is straight forward. You can access the web service methods like you access any other class.</p>
<p>Sometimes, the web service may prompt you to enter the login credentials to access the service. In this case, we will have to supply the user name and password. This can be done using the following steps:</p>
<p>NetworkCredential netCredential = new NetworkCredential(&#8220;username&#8221;, &#8220;password&#8221;);</p>
<p>client.UseDefaultCredentials = false;</p>
<p>client.Credentials = netCredential;</p>
<p>Read more about the Network credential class in msdn: <a href="http://www.three2tango.com/exchweb/bin/redir.asp?URL=http://msdn.microsoft.com/en-us/library/system.net.networkcredential(v=VS.90).aspx" target="_blank">http://msdn.microsoft.com/en-us/library/system.net.networkcredential(v=VS.90).aspx</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.three2tango.com/techcorner/create-a-web-service-client-from-wsdl-in-net.html/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to Bind Images from Database in a GridView</title>
		<link>http://www.three2tango.com/techcorner/how-to-bind-images-from-database-in-a-gridview.html/</link>
		<comments>http://www.three2tango.com/techcorner/how-to-bind-images-from-database-in-a-gridview.html/#comments</comments>
		<pubDate>Tue, 01 Dec 2009 14:22:28 +0000</pubDate>
		<dc:creator>Vivek</dc:creator>
				<category><![CDATA[ASP.Net]]></category>
		<category><![CDATA[GridView Tips]]></category>
		<category><![CDATA[Tech Corner]]></category>
		<category><![CDATA[Code# Code Snippets]]></category>
		<category><![CDATA[How to Bind Images from Database in a GridView]]></category>

		<guid isPermaLink="false">http://www.three2tango.com/?p=2733</guid>
		<description><![CDATA[Binding Images to a Gridview has been explained in this article. For this , first start a new application with ASP.NET and drop a GridView control onto the aspx page.Now add a new template Column to the GridView.In addition,if you want to display anything else, add bound fields or template fields according to your needs.In here, i have used a bound fied to display the image Id and the template field to display the Image.Now In the template field,add an Image control as the item template.For this just click on ...]]></description>
			<content:encoded><![CDATA[<p>Binding Images to a Gridview has been explained in this article. For this , first start a new application with ASP.NET and drop a GridView control onto the aspx page.Now add a new template Column to the GridView.In addition,if you want to display anything else, add bound fields or template fields according to your needs.In here, i have used a bound fied to display the image Id and the template field to display the Image.Now In the template field,add an Image control as the item template.For this just click on Edit Item Template and add an Image as Itemtemplate. Dont forget to uncheck the &#8216;AutoGenerateColumns&#8217; checkbox.The complete code for the GridView is as follows.</p>
<pre language="c-sharp" name="code">&lt;asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"&gt;
&lt;Columns&gt;
&lt;asp:BoundField HeaderText="ProductID" /&gt;
&lt;asp:TemplateField HeaderText="Image"&gt;
&lt;ItemTemplate&gt;
&lt;asp:Image ID="Image1" runat="server" /&gt;
&lt;/ItemTemplate&gt;
&lt;/asp:TemplateField&gt;
&lt;/Columns&gt;
&lt;/asp:GridView&gt;</pre>
<p>Now to display images. Here in the database,only the file names is there and hence if the images are in some directory, you have to somehow pre pend it with the filename.Here i am using the appsettings in web.config to provide the path of the images directory.</p>
<pre language="c-sharp" name="code">&lt;appSettings&gt;
&lt;add key="IMG" value="http://your full path"/&gt;
&lt;/appSettings&gt;</pre>
<p>Now to the C# code for populating the GridView. Here is the entire method i created for binding this GridView.</p>
<pre language="c-sharp" name="code">private void bindGrid()
{
string strconn= ConfigurationManager.ConnectionStrings["YourConnectionString"].ConnectionString;
SqlConnection con = new SqlConnection(strconn);
con.Open();
string cmdText = "Select productId,Filename from Images"
SqlCommand cmd = new SqlCommand(cmdText, con);
cmd.CommandType = CommandType.Text;
DataTable dt = new DataTable();
SqlDataAdapter da = new SqlDataAdapter(cmd);
da.Fill(dt);
GridView1.DataSource = dt;
GridView1.DataBind();

for (int i = 0; i &lt; dt.Rows.Count; i++)
{
GridView1.Rows[i].Cells[0].Text = dt.Rows[i]["ProductId"].ToString();
GridView1.Rows[i].Cells[2].Text = dt.Rows[i]["Filename"].ToString();
Image PImage = (Image)GridView1.Rows[i].FindControl("Image1");
PImage.ImageUrl = ConfigurationManager.AppSettings["IMG"].ToString() + dt.Rows[i]["FileName"].ToString();
}
con.Close();
}</pre>
<p>Though this method will be slow if you want to populate huge amount of data, it is quite effective. Now here in the first line, i am taking the connection string from the  web.config.The next few steps are self explanatory as you can see.You may be wondering why i have binded the Grid and after that i am populating it again. That is because, when the for loop runs, if the GridView is not binded, the Index was out of range index error will be shown.<br />
Now in the for loop, the first cell, which contains the bound field, text is set to the ImageId. The second line in the loop, we are finding the image control we had added before as the template field in the GridView.&#8221;Image1&#8243; is the ID of the Image Control.Now all that is remaining is setting the ImageUrl property of the found image control. Before that we prepend the FileName with the directory path.</p>
<p>Hope this helps.As i said, this method may be slow if you have many images to be populated.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.three2tango.com/techcorner/how-to-bind-images-from-database-in-a-gridview.html/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Populating ASP.NET TreeView Control from DataBase</title>
		<link>http://www.three2tango.com/techcorner/populating-asp-net-treeview-control-from-database.html/</link>
		<comments>http://www.three2tango.com/techcorner/populating-asp-net-treeview-control-from-database.html/#comments</comments>
		<pubDate>Tue, 27 Oct 2009 09:46:45 +0000</pubDate>
		<dc:creator>Vivek</dc:creator>
				<category><![CDATA[ASP.Net]]></category>
		<category><![CDATA[C# Codes]]></category>
		<category><![CDATA[Tech Corner]]></category>
		<category><![CDATA[C# Code Snippets]]></category>
		<category><![CDATA[TreeView]]></category>

		<guid isPermaLink="false">http://www.three2tango.com/?p=2636</guid>
		<description><![CDATA[Here i will explain the binding of a treeview from the Database.This can be a tricky task since we may have to build a parent-child relationship here.So first thing you would need is a table in the database where we actually have the parent-child relationship.
An Example
Table Name: Category
CategoryId  INT
CategoryName  Varchar(50)
ParentCategoryId INT
NodeLevel  INT
Suppose we have Data in the Table named Category as follows



1
Root
NULL
0


2
Child
1
1


3
Child2
1
1


4
grandChild
2
2


5
grandChild2
2
2


6
grandChild3
3
2



// 

Now to bind this to the tree,we will use a recursive function.Also for better performance,we will bind the database results into a global DataTable first and then apply filtering.
Here is the Code ...]]></description>
			<content:encoded><![CDATA[<p>Here i will explain the binding of a treeview from the Database.This can be a tricky task since we may have to build a parent-child relationship here.So first thing you would need is a table in the database where we actually have the parent-child relationship.<br />
An Example<br />
Table Name: Category<br />
CategoryId  INT<br />
CategoryName  Varchar(50)<br />
ParentCategoryId INT<br />
NodeLevel  INT</p>
<p>Suppose we have Data in the Table named Category as follows</p>
<table border="1">
<tbody>
<tr>
<td>1</td>
<td>Root</td>
<td>NULL</td>
<td>0</td>
</tr>
<tr>
<td>2</td>
<td>Child</td>
<td>1</td>
<td>1</td>
</tr>
<tr>
<td>3</td>
<td>Child2</td>
<td>1</td>
<td>1</td>
</tr>
<tr>
<td>4</td>
<td>grandChild</td>
<td>2</td>
<td>2</td>
</tr>
<tr>
<td>5</td>
<td>grandChild2</td>
<td>2</td>
<td>2</td>
</tr>
<tr>
<td>6</td>
<td>grandChild3</td>
<td>3</td>
<td>2</td>
</tr>
</tbody>
</table>
<p><script type="text/javascript">// <![CDATA[
           google_ad_client = "pub-6525089797582043"; /* 468x15, created 7/8/09 */ google_ad_slot = "8684679217"; google_ad_width = 468; google_ad_height = 15;
// ]]&gt;</script><br />
<script src="http://pagead2.googlesyndication.com/pagead/show_ads.js" type="text/javascript"></script><br />
Now to bind this to the tree,we will use a recursive function.Also for better performance,we will bind the database results into a global DataTable first and then apply filtering.</p>
<p>Here is the Code to bind to the DataTable.</p>
<pre name="code" language="c-sharp"> private void bindDataTable()
    {
       
        string strConn = ConfigurationManager.ConnectionStrings["yourConnectionName"].ConnectionString;
        SqlConnection conn = new SqlConnection(strConn);
        SqlCommand cmd = new SqlCommand("Select * from Category", conn);
        cmd.CommandType = CommandType.Text;
       
        SqlDataAdapter sqlDa = new SqlDataAdapter();
        sqlDa.SelectCommand = cmd;
        sqlDa.Fill(dt);
        conn.Close();

    }</pre>
<p>Now we will add a recursive method that will make use of this DataTable to build the TreeView.</p>
<pre name="code" language="c-sharp">private void buildNodes(TreeNode n, int? categoryId)
    {
        DataRow[] drCategories;
        if (categoryId == null)
            drCategories = dt.Select("NodeLevel=0"); // This will get the Root Node
        else
            drCategories = dt.Select("ParentIdFK='" + categoryId + "'");

        foreach (DataRow dr in drCategories)
        {
            TreeNode t = new TreeNode();
            t.Text = dr["CategoryName"].ToString();
            t.Value = dr["CategoryId"].ToString();    
           
            buildNodes(t, Convert.ToInt32(dr["CategoryId"].ToString()));// Calling the function resursively
            if (n == null)// If it is Root Node
                TreeView1.Nodes.Add(t);
            else
                n.ChildNodes.Add(t);

        }</pre>
<p>Above we are using int? so that int type can accept null values.</p>
<p>So now all we have to do is call these methods.</p>
<pre name="code" language="c-sharp">  protected void Page_Load(object sender, EventArgs e)
     {
         if (!IsPostBack)
         {
              bindDataTable();
              buildNodes(null, null);//CategoryId=null is passed which is the ParentId of the Root Node
         }
     }</pre>
<p>Now you can add some formatting and Css as you may please to get a better looking Treeview.Happy Coding Folks!!!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.three2tango.com/techcorner/populating-asp-net-treeview-control-from-database.html/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>&#8216;Thread was being aborted&#8217;on using Response.Redirect,Response.End</title>
		<link>http://www.three2tango.com/techcorner/thread-was-being-abortedon-using-response-redirectresponse-end.html/</link>
		<comments>http://www.three2tango.com/techcorner/thread-was-being-abortedon-using-response-redirectresponse-end.html/#comments</comments>
		<pubDate>Wed, 21 Oct 2009 12:20:03 +0000</pubDate>
		<dc:creator>Vivek</dc:creator>
				<category><![CDATA[ASP.Net]]></category>
		<category><![CDATA[Tech Corner]]></category>
		<category><![CDATA['Thread was being aborted'on using Response.Redirect]]></category>
		<category><![CDATA[Response.End-How to Resolve]]></category>

		<guid isPermaLink="false">http://www.three2tango.com/?p=2634</guid>
		<description><![CDATA[This is a very common error that is encountered.This is because Response.End ends the Page Execution and transfers the execution to Application_EndRequest event and the line following the Response.End is not executed.
This problem occurs for the Response.Redirect method also as when this method is used, an internal call to Response.End is made.
// 

How to resolve it?
Instead of Response.End,use HttpContext.Current.ApplicationInstance.CompleteRequest method.
For Response.Redirect,set the endResponse parameter in the method to false.It indicates that the execution of the current page should not terminate.
Eg:

Response.Redirect("~/Default.aspx",false);
This error also happens when Server.Transfer method is called.Just use Server.Execute ...]]></description>
			<content:encoded><![CDATA[<p>This is a very common error that is encountered.This is because Response.End ends the Page Execution and transfers the execution to Application_EndRequest event and the line following the Response.End is not executed.<br />
This problem occurs for the Response.Redirect method also as when this method is used, an internal call to Response.End is made.<br />
<script type="text/javascript">// <![CDATA[
           google_ad_client = "pub-6525089797582043"; /* 468x15, created 7/8/09 */ google_ad_slot = "8684679217"; google_ad_width = 468; google_ad_height = 15;
// ]]&gt;</script><br />
<script src="http://pagead2.googlesyndication.com/pagead/show_ads.js" type="text/javascript"></script><br />
<strong>How to resolve it?</strong><br />
Instead of Response.End,use HttpContext.Current.ApplicationInstance.CompleteRequest method.<br />
For Response.Redirect,set the endResponse parameter in the method to false.It indicates that the execution of the current page should not terminate.<br />
Eg:
<pre name="code" language="c-sharp">
Response.Redirect("~/Default.aspx",false);</pre>
<p>This error also happens when Server.Transfer method is called.Just use Server.Execute method instead. </p>
]]></content:encoded>
			<wfw:commentRss>http://www.three2tango.com/techcorner/thread-was-being-abortedon-using-response-redirectresponse-end.html/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>.Net Framework 4.0 -New Features in Core Services</title>
		<link>http://www.three2tango.com/techcorner/net-framework-4-0-new-features-in-core-services.html/</link>
		<comments>http://www.three2tango.com/techcorner/net-framework-4-0-new-features-in-core-services.html/#comments</comments>
		<pubDate>Wed, 21 Oct 2009 06:42:11 +0000</pubDate>
		<dc:creator>Vivek</dc:creator>
				<category><![CDATA[ASP.Net]]></category>
		<category><![CDATA[Tech Corner]]></category>
		<category><![CDATA[.Net 4.0]]></category>

		<guid isPermaLink="false">http://www.three2tango.com/?p=2631</guid>
		<description><![CDATA[THe Visual Studio 2010 Beta and the .Net Framework 4.0 were launched by Microsoft Corporation this week.With the launch comes many new features that will sure take applicatipn and web development to new heights.The basic structure still quite remains the same but still the product does come with many new exciting features.The changes have come mainly in the core services,Ajax,Web Forms etc.
// 

The core services like Output caching and session state storage makes a significant improvement.One of these is the Web.Configminification.The introduction of new features meant that the web.config was ...]]></description>
			<content:encoded><![CDATA[<p>THe Visual Studio 2010 Beta and the .Net Framework 4.0 were launched by Microsoft Corporation this week.With the launch comes many new features that will sure take applicatipn and web development to new heights.The basic structure still quite remains the same but still the product does come with many new exciting features.The changes have come mainly in the core services,Ajax,Web Forms etc.<br />
<script type="text/javascript">// <![CDATA[
           google_ad_client = "pub-6525089797582043"; /* 468x15, created 7/8/09 */ google_ad_slot = "8684679217"; google_ad_width = 468; google_ad_height = 15;
// ]]&gt;</script><br />
<script src="http://pagead2.googlesyndication.com/pagead/show_ads.js" type="text/javascript"></script><br />
The core services like Output caching and session state storage makes a significant improvement.One of these is the <em>Web.Config</em>minification.The introduction of new features meant that the web.config was becoming harder to configure.But in .Net Framework 4.0,the major configuration elements have been moved to the machine.config file and the application just inherits these settings.It means that the web.config file is nearly empty of configuration elements and we can use it mostly for user defined configuration settings.</p>
<p>Another new feature in the core services is the extensible Output Caching which allows you to configure one or more custom output-cache providers.These providers may be local or remote disks,cloud storages or distributed cache engines.This would mean that the caching ,which was making servers with heavy traffic inefficient, will not have to worry much about the memory.The .Net 4.0 comes with a new System.web.OutputProvider class which allows you to create custom output cache providers.</p>
<p>The new Auto-Start feature for Web applications provides a controlled approach to start an application pool,thus making the process of &#8216;waking-up&#8217; the application for its first request much faster.</p>
<p>The RedirectPermanent helper class makes it easy to issue HTTP 301 moved Permanently responses,just reducing the number of HTTP round trips that was needed when Response.Redirect() method was used.</p>
<p>The storage of session states could sometimes take up large amount of memory for storing the serialized data..Net 4.0 introduces a new compression option which uses the System.IO.Compression.GZipStream  class.</p>
<p>These are some of the many new core services features available in the .Net 4.0.The web forms also has many new features like</p>
<ol>The ability to set meta tags.<br />
More control over view state.<br />
Easier ways to work with browser capabilities.<br />
Support for using ASP.NET routing with Web Forms.<br />
More control over generated IDs.<br />
The ability to persist selected rows in data controls.<br />
More control over rendered HTML in the FormView and ListView controls.<br />
Filtering support for data source controls.</ol>
<p>For all the new features and explanation about them,visit <a href="http://www.asp.net/learn/whitepapers/aspnet40/" target="_blank">asp.net</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.three2tango.com/techcorner/net-framework-4-0-new-features-in-core-services.html/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Creating your first WebService using .NET</title>
		<link>http://www.three2tango.com/techcorner/creating-your-first-webservice-using-net.html/</link>
		<comments>http://www.three2tango.com/techcorner/creating-your-first-webservice-using-net.html/#comments</comments>
		<pubDate>Mon, 19 Oct 2009 12:30:07 +0000</pubDate>
		<dc:creator>Vivek</dc:creator>
				<category><![CDATA[ASP.Net]]></category>
		<category><![CDATA[Tech Corner]]></category>
		<category><![CDATA[.NET Web Services]]></category>

		<guid isPermaLink="false">http://www.three2tango.com/?p=2618</guid>
		<description><![CDATA[Now that we have learnt some basic stuff about about what web services are  and how they communicate,lets build our first webservice using Visual Studio.I have done this in VS 2008.
First Step: Open Visual Studio.Click on File and then select &#8220;New WebSite&#8221;.From the Next Window that appears,click ASP&#62;NET Web Service.Select your language and then click OK.
By Default,VS 2008 will automatically create your first WebService &#8220;Hello World&#8221;.Notice that the Class inherits the System.Web.Services.WebService Class.
public class Service : System.Web.Services.WebService
Also,before the method &#8220;Hello World&#8221;,a [WebMethod] attributed has been specified.This basically tells the compiller ...]]></description>
			<content:encoded><![CDATA[<p>Now that we have learnt some <a href="http://www.three2tango.com/techcorner/net-web-service-basics-and-interview-questions.html/" target="_blank">basic stuff about about what web services are </a> and how they communicate,lets build our first webservice using Visual Studio.I have done this in VS 2008.</p>
<p>First Step: Open Visual Studio.Click on File and then select &#8220;New WebSite&#8221;.From the Next Window that appears,click ASP&gt;NET Web Service.Select your language and then click OK.</p>
<p>By Default,VS 2008 will automatically create your first WebService &#8220;Hello World&#8221;.Notice that the Class inherits the System.Web.Services.WebService Class.</p>
<pre>public class Service : System.Web.Services.WebService</pre>
<p>Also,before the method &#8220;Hello World&#8221;,a [WebMethod] attributed has been specified.This basically tells the compiller to expose the method.</p>
<pre name="code" language="c-sharp">    [WebMethod]
    public string HelloWorld() {
        return "Hello World";
    }</pre>
<p><script type="text/javascript">// <![CDATA[
            google_ad_client = "pub-6525089797582043"; /* 468x15, created 7/8/09 */ google_ad_slot = "8684679217"; google_ad_width = 468; google_ad_height = 15;
// ]]&gt;</script><br />
<script src="http://pagead2.googlesyndication.com/pagead/show_ads.js" type="text/javascript"></script><br />
Attaching the WebMethod attribute to the method indicates that you want to expose this method as part of the XML Web Service.To further configure the behavior of the method,we can make use of the properties in the WebMethod attribute.<a href="http://msdn.microsoft.com/en-us/library/byxd99hx(VS.71).aspx" target="_blank">See the different properties of the WebMethod Attribute</a></p>
<p> Now if you run the project,you will get the following.</p>
<p><a href="http://www.three2tango.com/wp-content/uploads/2009/10/WebServiceExample.JPG"><img class="aligncenter size-medium wp-image-2619" title="WebServiceExample" src="http://www.three2tango.com/wp-content/uploads/2009/10/WebServiceExample-300x225.jpg" alt="WebServiceExample" width="300" height="225" /></a></p>
<p>Now if we select the HelloWorld method,ypu will get the next screen that allows you to invoke the method.On invoking the method,you will get the XML output of the method &#8216;HelloWorld&#8217;.</p>
<p><a href="http://www.three2tango.com/wp-content/uploads/2009/10/WebServiceExample1.JPG"><img class="aligncenter size-medium wp-image-2620" title="WebServiceExample1" src="http://www.three2tango.com/wp-content/uploads/2009/10/WebServiceExample1-300x225.jpg" alt="WebServiceExample1" width="300" height="225" /></a></p>
<p>Now lets just create a more meaningful Method to be exposed and make use of the properties of the WebMethod attribute I am creating a Class named Product and i will output the Product Class object.Here is the Class</p>
<pre name="code" language="c-sharp">public class Product
{
 public Product()
 {
  //
  // TODO: Add constructor logic here
  //
 }  
    public string productName;
    public string productPrice;
}</pre>
<p>Now the Web Service Method for getting ProductDetails.I have added the EnableSession and Description Properties to the WebMethod attribute.</p>
<pre name="code" language="c-sharp">[WebMethod(EnableSession=true,Description="Gets the Product Details")]
    public Product getProductDetails()
    {
        Product p = new Product();
        p.productName = "xxx";
        p.productPrice = "$12.00";
        return p;
    }</pre>
<p>The Output on invoking this method will be</p>
<p> <a href="http://www.three2tango.com/wp-content/uploads/2009/10/WebServiceExample2.jpg"><img title="WebServiceExample2" src="http://www.three2tango.com/wp-content/uploads/2009/10/WebServiceExample2-300x225.jpg" alt="WebServiceExample2" width="300" height="225" /></a></p>
<p>Now suppose you want to change the display Xml node to something other than productName and productPrice.For that use the System.Xml.Serialization namespace and do the following.</p>
<pre name="code" language="c-sharp">public class Product
{
 public Product()
 {
  //
  // TODO: Add constructor logic here
  //
 }
    [XmlElement(ElementName="Name")]
    public string productName;
    [XmlElement(ElementName="Price")]
    public string productPrice;
}</pre>
<p>Now,instead of showing the node name as productName and productPrice,it will be shown as Name and Price.</p>
<p>Like this there are many Classes in the Xml.Serialization namespace that can be used to enhance the output of your Webservice.</p>
<p>Now having created the WebService,lets build a simple client application that uses this WebService.The easiest way is to add a Web Reference to your project.So create a new WebSite or any application.Right click the Solution Explorer and select Add Web Reference. Now on the next dialog box,you will be asked to provide the URL of the WebService.Provide that and also give a name for the reference.Suppose you name ws.3 files will be created.A discoveryfile disco,discovery map file .discoMap and a wsdl file.<br />
Now to access the webservice you will have to create an object of the same.</p>
<pre>ws.Service obj=new ws.Service();</pre>
<p>To access the method getProductDetails(),create an object of Product and call the method,just like calling a simple method</p>
<pre name="code" language="c-sharp">ws.Product p=new ws.Product();
p=obj.getProductDetails();</pre>
<p>That completes our first Tutorial to build a simple XML WebService using .Net.I will come up with more on Web Services in the future.Hope you will enjoy Web Service Programming.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.three2tango.com/techcorner/creating-your-first-webservice-using-net.html/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>.NET Web Service Basics and Interview Questions</title>
		<link>http://www.three2tango.com/techcorner/net-web-service-basics-and-interview-questions.html/</link>
		<comments>http://www.three2tango.com/techcorner/net-web-service-basics-and-interview-questions.html/#comments</comments>
		<pubDate>Wed, 14 Oct 2009 05:09:42 +0000</pubDate>
		<dc:creator>Vivek</dc:creator>
				<category><![CDATA[ASP.Net]]></category>
		<category><![CDATA[Tech Corner]]></category>
		<category><![CDATA[Technical Interview]]></category>
		<category><![CDATA[.NET interview questions]]></category>
		<category><![CDATA[.NET Web Services]]></category>

		<guid isPermaLink="false">http://www.three2tango.com/?p=2591</guid>
		<description><![CDATA[Explain .Net Web Service?
A Web service allows you to publish an application&#8217;s function on the internet that can be accessed through another application.A very common example is the currency exchange rates available in many web sites.In most of the cases,this module will not even reside on the server on which the web site has been uploaded,but it may be using a webservice that gives the functionality.In Short, Web services are components that can be used by other applications.The definite advantage is reusability and that web services are platform and language ...]]></description>
			<content:encoded><![CDATA[<p>Explain .Net Web Service?<br />
A Web service allows you to publish an application&#8217;s function on the internet that can be accessed through another application.A very common example is the currency exchange rates available in many web sites.In most of the cases,this module will not even reside on the server on which the web site has been uploaded,but it may be using a webservice that gives the functionality.In Short, Web services are components that can be used by other applications.The definite advantage is reusability and that web services are platform and language independent as it uses a standardized XML messaging system.<br />
ASP.NET offers easy way to develop web service.To qualify a class as a web service,you can either make the class inherit from the System.Web.Services.WebService or by qualifying the class with the [WebService] attribute.To make a method in the webservice accessible over the internet,just precede the method with a special [WebMethod] attribute in order them to work as Web Service.The web service will have an interface that describes all the methods.This is accompolished by the WSDL (Web Services Description Language).TO locate the webservice so that you can use it in your application,we make use of the UDDI (Universal Description, Discovery and Integration).<br />
However in .Net,you would not need to worry about WSDL and UDDI.To use it in your application,you can just add the service as a web reference by supplying its URL.<br />
What is SOAP?<br />
SOAP- Simple Object Access Protocol is a communication protocol based on XML standards.Web Service uses SOAP for communication.Web Services can also use HTTP GET and POST,but the use of SOAP is preferred since it allows you to transmit complex data also.Http-Get and Http-Post works with name/value pair which means transferring complex object is not possible with these protocols,whereas SOAP serializes complex structure, such as ASP.NET DataSets, complex arrays, custom types and XML nodes before transmitting and thus allows exchange of complex objects between applications. SOAP uses HTTP channel to transport which makes it widely accepted protocol over the internet and dos not face the compactibility and security issues faced by a Remote Procedure call.</p>
<p>What is WSDL?<br />
WSDL stands for Web Services Description Language, an XML-based language that describes Web services and how to access and locate them.</p>
<p>What is UDDI?<br />
UDDI stands for Universal Description, Discovery and Integration. It is an open, Internet-based specification that offers directory service for storing information about web services.</p>
<p>What are the protocols a .Net Web Service uses.<br />
In .Net, a web service is bind with three different protocols such as HTTP/POST, HTTP/GET, and SOAP,allowing client with three options to choose for communication. These protocols are included in the WSDL file that is automatically generated in .NET.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.three2tango.com/techcorner/net-web-service-basics-and-interview-questions.html/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>ConfigurationManager Class and the use of web.config file</title>
		<link>http://www.three2tango.com/techcorner/configurationmanager-class-and-the-use-of-web-config-file.html/</link>
		<comments>http://www.three2tango.com/techcorner/configurationmanager-class-and-the-use-of-web-config-file.html/#comments</comments>
		<pubDate>Wed, 07 Oct 2009 18:01:04 +0000</pubDate>
		<dc:creator>Vivek</dc:creator>
				<category><![CDATA[ASP.Net]]></category>
		<category><![CDATA[Tech Corner]]></category>
		<category><![CDATA[C# Code Snippets]]></category>
		<category><![CDATA[ConfigurationManager Class]]></category>

		<guid isPermaLink="false">http://www.three2tango.com/?p=2549</guid>
		<description><![CDATA[Some of the values and strings,for example the connection string, are used across all the pages of a website. Now to hard code this in each of the pages where it is needed is a tedious process as a change has to be updated in each of them.So what we do is to make use of the web.config file in the application to store these values.
There are two methods to store the connection string or any other value in the web.config file.Either you can add a key and value pair ...]]></description>
			<content:encoded><![CDATA[<p>Some of the values and strings,for example the connection string, are used across all the pages of a website. Now to hard code this in each of the pages where it is needed is a tedious process as a change has to be updated in each of them.So what we do is to make use of the web.config file in the application to store these values.</p>
<p>There are two methods to store the connection string or any other value in the web.config file.Either you can add a key and value pair inside the &lt;appSetting&gt; element or make a custom section of your own in the web.config.To retrieve the values in the custom section defined,ASP.NET 2.0 provides you with the ConfigurationManager Class.</p>
<p>Let&#8217;s see both the methods of defining a connection string.<br />
First in the &lt;appSetting&gt; element</p>
<pre name="code" class="c-sharp">&lt;appSettings&gt;
&lt;add key="connectionString" value="connection string value" /&gt;
&lt;/appSettings&gt;</pre>
<p>Now to retrieve this,we can use the following code in the application</p>
<pre name="code" class="c-sharp">string strConn=ConfigurationSettings.AppSettings("connectionString");
SqlConnection conn=new SqlConnection(strconn);</pre>
<p>Here the connection string is stored as key and value pair in the &lt;appSettings&gt; element of the web.config file.</p>
<p>Instead of using the &lt;appSettings&gt; section you can also add your own sections in the web.config file to have all your string value that you will be using in your application.<br />
ASP.Net 2.0 provides with a special class for retrieving those customized string values. This class is called the ConfigurationManager class.</p>
<p>Now here we are using a custom section to store the connection string</p>
<p>Now to use the ConnectionStrings section of the web.config file, you can use code like</p>
<pre name="code" class="c-sharp">ConfigurationManager.ConnectionStrings["connection_name"].ConnectionString</pre>
<p>The namespace to be added is <em>System.Configuration</em></p>
<p>Here is another use of the class.</p>
<p>In the web.config,you add the following code,which gives an URL,which is used in many files and may change in the future.</p>
<pre name="code" class="c-sharp">&lt;appSettings&gt;
&lt;add key="URL" value="<a href="http://www.three2tango.com/&quot;/">http://www.three2tango.com/"/</a>&gt;
&lt;/appSettings&gt;</pre>
<p>Nowto use it  ,you can make use of the ConfigurationManager class</p>
<pre name="code" class="c-sharp">string URL=ConfigurationManager.AppSettings.Get("URL");</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.three2tango.com/techcorner/configurationmanager-class-and-the-use-of-web-config-file.html/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Convert a String in CSV format to INT Array in .NET</title>
		<link>http://www.three2tango.com/techcorner/convert-a-string-in-csv-format-to-int-array-in-net.html/</link>
		<comments>http://www.three2tango.com/techcorner/convert-a-string-in-csv-format-to-int-array-in-net.html/#comments</comments>
		<pubDate>Tue, 06 Oct 2009 17:27:12 +0000</pubDate>
		<dc:creator>Vivek</dc:creator>
				<category><![CDATA[ASP.Net]]></category>
		<category><![CDATA[C# Codes]]></category>
		<category><![CDATA[Tech Corner]]></category>
		<category><![CDATA[C# Code Snippets]]></category>
		<category><![CDATA[Convert a String in CSV format to INT Array in .NET]]></category>

		<guid isPermaLink="false">http://www.three2tango.com/?p=2540</guid>
		<description><![CDATA[There may be many instances in which we may have to supply a string in CSV format to be converted into an integer array.For example,if we have to invoke a web method in a web service in which the parameters to be passed is an integer array.There is no way that we can pass an Integer array to the web method,else you would have to have a client application to test the method.Well,this was the instance in which i had the need to pass these integers in CSV format as ...]]></description>
			<content:encoded><![CDATA[<p>There may be many instances in which we may have to supply a string in CSV format to be converted into an integer array.For example,if we have to invoke a web method in a web service in which the parameters to be passed is an integer array.There is no way that we can pass an Integer array to the web method,else you would have to have a client application to test the method.Well,this was the instance in which i had the need to pass these integers in CSV format as a string and get the result.</p>
<p>Here is the code to  convert a string in CSV format ot an integer array.</p>
<pre name="code" class="c-sharp">
 
public int[] StringToArray(string input)
        {
            string[] stringList = input.Split(",".ToCharArray(),
                                              StringSplitOptions.RemoveEmptyEntries);
           
            int[] ids = new int[stringList.Length];

            for (int i = 0; i &lt; stringList.Length; i++)
            {
                ids[i] = (int)Convert.ChangeType(stringList[i], typeof(int));
            }

            return ids;  
        }
</pre>
<p> <br />
Here instead of the &#8220;,&#8221; delimiter you can make use of the delimiter used in your format</p>
]]></content:encoded>
			<wfw:commentRss>http://www.three2tango.com/techcorner/convert-a-string-in-csv-format-to-int-array-in-net.html/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>XML serialization of Objects in .NET</title>
		<link>http://www.three2tango.com/techcorner/xml-serialization-of-objects-in-net.html/</link>
		<comments>http://www.three2tango.com/techcorner/xml-serialization-of-objects-in-net.html/#comments</comments>
		<pubDate>Mon, 05 Oct 2009 17:12:52 +0000</pubDate>
		<dc:creator>Vivek</dc:creator>
				<category><![CDATA[ASP.Net]]></category>
		<category><![CDATA[C# Codes]]></category>
		<category><![CDATA[Tech Corner]]></category>
		<category><![CDATA[C# Code Snippets]]></category>
		<category><![CDATA[XML serialization of Objects in .NET]]></category>

		<guid isPermaLink="false">http://www.three2tango.com/?p=2538</guid>
		<description><![CDATA[Serialization is a process by which information in an object is converted into a persistable and transportable form.Here i will explain the easiest way to do XML Serialization,which converts (serializes) the public fields and properties  of an object, or the parameters and return values of methods, into an XML stream that conforms to a specific XML Schema definition language (XSD) document.
To explain the basics of serialization,lets create a class Product containing information about a Product
Public Class Product()
{
public product(){ }
public string productName;
public float productPrice;
}
Now to create an XML representation of the object ...]]></description>
			<content:encoded><![CDATA[<p>Serialization is a process by which information in an object is converted into a persistable and transportable form.Here i will explain the easiest way to do XML Serialization,which converts (serializes) the public fields and properties  of an object, or the parameters and return values of methods, into an XML stream that conforms to a specific XML Schema definition language (XSD) document.<br />
To explain the basics of serialization,lets create a class Product containing information about a Product</p>
<pre name="code" language="c-sharp">Public Class Product()
{
public product(){ }
public string productName;
public float productPrice;
}</pre>
<p>Now to create an XML representation of the object of class Product,we can make use of the XmlSerializer class in .Net.Here is the C# code for implementing serialization.</p>
<pre name="code" language="c-sharp">Product p=new Product();
p.productName="product1";
p.productPrice=12.00;
XmlSerializer serializer=new XmlSerializer(typeOf(Product));
StringWriter sw=new StringWriter();
serializer.Serialize(sw,p);
sw.Close(); </pre>
<p> <br />
Here is another example.In the below code,i have an object of class Product,which contains Product Information.when i run the webservice,i have to pass the ProductId(second line) to get the information and the webservice will automatically generate an XML file containing the details.Now what do we do if we have to save this information to another XML file so that we have the information even after the web service is stopped or in more technical terms we want the data to be persistent.</p>
<p>Namespace used: <em>System.Xml.Serialization</em>;      </p>
<pre name="code" class="c-sharp">Product productXml = new Product();
productXml = application.getProducts().getProductInfo(id);//build the product object
XmlSerializer serialize = new XmlSerializer(typeof(Product));
TextWriter tw = new StreamWriter(Server.MapPath("Products.xml"));
serialize.Serialize(tw, productXml);
tw.Close();</pre>
<p>Dont forget to include System.IO,else you wont be able to use TextWriter and StreamWriter.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.three2tango.com/techcorner/xml-serialization-of-objects-in-net.html/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

