<?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/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>Asp.Net Team's Weblog &#187; Connectionstring</title>
	<atom:link href="http://aspnetteam.wordpress.com/tag/connectionstring/feed/" rel="self" type="application/rss+xml" />
	<link>http://aspnetteam.wordpress.com</link>
	<description>Another ASP.NET Weblog</description>
	<lastBuildDate>Thu, 03 Sep 2009 11:54:33 +0000</lastBuildDate>
	<generator>http://wordpress.com/</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<cloud domain='aspnetteam.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://www.gravatar.com/blavatar/ea6345954410fcd98c45fab481df7cbf?s=96&#038;d=http://s.wordpress.com/i/buttonw-com.png</url>
		<title>Asp.Net Team's Weblog &#187; Connectionstring</title>
		<link>http://aspnetteam.wordpress.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://aspnetteam.wordpress.com/osd.xml" title="Asp.Net Team&#8217;s Weblog" />
		<item>
		<title>Using Web Services: How to Create</title>
		<link>http://aspnetteam.wordpress.com/2008/09/11/using-web-services-how-to-create/</link>
		<comments>http://aspnetteam.wordpress.com/2008/09/11/using-web-services-how-to-create/#comments</comments>
		<pubDate>Thu, 11 Sep 2008 18:25:41 +0000</pubDate>
		<dc:creator>Frank Adams</dc:creator>
				<category><![CDATA[WebServices]]></category>
		<category><![CDATA[Connectionstring]]></category>
		<category><![CDATA[Dataset]]></category>
		<category><![CDATA[Dim]]></category>
		<category><![CDATA[Imports]]></category>

		<guid isPermaLink="false">http://aspnetteam.wordpress.com/?p=25</guid>
		<description><![CDATA[This post will go into how to create a web service using VS. 
 
The first thing that needs to be done is create a web site and choose ASP.NET Web Service from the Template window.  If you are thinking about using the web service as it is intended for, reusability, then you will want to [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=aspnetteam.wordpress.com&blog=4774049&post=25&subd=aspnetteam&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p class="MsoNormal" style="margin:0;"><span style="font-size:12pt;font-family:Arial;">This post will go into how to create a web service using VS. </span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:12pt;font-family:Arial;"><span> </span></span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:12pt;font-family:Arial;">The first thing that needs to be done is create a web site and choose ASP.NET Web Service from the Template window.<span>  </span>If you are thinking about using the web service as it is intended for, reusability, then you will want to place it in a directory folder that will be accessible to all application that can use it on the intranet (although you can reference a web service by using a web address, we will not go into that). An example of a folder would be ‘WebServices’. This folder would hold all web service created. We will name this web service ‘getAllStationInfo’.</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:12pt;font-family:Arial;"> </span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:12pt;font-family:Arial;">Once you have your web site started you will see that the default page opens up and is ready for coding.<span>  </span>It has already imported the namespaces needed at the top and has a public class named Service.<span>  </span>We will be adding more namespaces to ours because of the nature of the service – database query.<span>  </span>It will look like the below: </span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:12pt;font-family:Arial;"> </span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-family:Times New Roman;"><span style="font-size:12pt;color:#0000ff;">Imports</span><span style="font-size:12pt;"> System.Web</span></span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-family:Times New Roman;"><span style="font-size:12pt;color:#0000ff;">Imports</span><span style="font-size:12pt;"> System.Web.Services</span></span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-family:Times New Roman;"><span style="font-size:12pt;color:#0000ff;">Imports</span><span style="font-size:12pt;"> System.Web.Services.Protocols</span></span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-family:Times New Roman;"><span style="font-size:12pt;color:#0000ff;">Imports</span><span style="font-size:12pt;"> System.Data.SqlClient</span></span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-family:Times New Roman;"><span style="font-size:12pt;color:#0000ff;">Imports</span><span style="font-size:12pt;"> System.Data</span></span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:12pt;"><span style="font-family:Times New Roman;"> </span></span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:12pt;font-family:Arial;">It also has its first function called HelloWorld() for editing. All we are going to do this time is create a web method that can be consumed. Here is what it looks like at first:</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:12pt;font-family:Arial;"> </span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:12pt;"><span style="font-family:Times New Roman;">&lt;WebMethod()&gt; _</span></span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:12pt;"><span style="font-family:Times New Roman;"><span>    </span><span style="color:#0000ff;">Public</span> <span style="color:#0000ff;">Function</span> HelloWorld() <span style="color:#0000ff;">As</span> <span style="color:#0000ff;">String</span></span></span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:12pt;"><span style="font-family:Times New Roman;"><span>        </span><span style="color:#0000ff;">Return</span> <span style="color:#a31515;">&#8220;Hello World&#8221;</span></span></span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-family:Times New Roman;"><span style="font-size:12pt;"><span>    </span><span style="color:#0000ff;">End</span> <span style="color:#0000ff;">Function</span></span><span style="font-size:12pt;"> </span></span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:12pt;font-family:Arial;"> </span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:12pt;font-family:Arial;">This is what a finished one looks like:</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:12pt;font-family:Arial;"> </span></p>
<p class="MsoNormal" style="margin:0;"><a name="OLE_LINK2"></a><a name="OLE_LINK1"><span><span style="font-size:12pt;"><span style="font-family:Times New Roman;">&lt;WebMethod()&gt; _</span></span></span></a> </p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:12pt;"><span style="font-family:Times New Roman;"><span>    </span><span style="color:#0000ff;">Public</span> <span style="color:#0000ff;">Function</span> getAllStationInfo() <span style="color:#0000ff;">As</span> DataSet</span></span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:12pt;"><span style="font-family:Times New Roman;"><span>        </span><span style="color:#0000ff;">Dim</span> conn <span style="color:#0000ff;">As</span> <span style="color:#0000ff;">New</span> SqlConnection(ConfigurationManager.ConnectionStrings(<span style="color:#a31515;">&#8220;DatabaseNameHere&#8221;</span>).ConnectionString)</span></span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:12pt;"><span style="font-family:Times New Roman;"><span>        </span>conn.Open()</span></span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:12pt;"><span style="font-family:Times New Roman;"><span>        </span><span style="color:#0000ff;">Dim</span> adapter <span style="color:#0000ff;">As</span> <span style="color:#0000ff;">New</span> SqlDataAdapter(<span style="color:#a31515;">&#8220;Select statement&#8221;</span>, conn)</span></span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:12pt;"><span style="font-family:Times New Roman;"><span>        </span><span style="color:#0000ff;">Dim</span> ds <span style="color:#0000ff;">As</span> <span style="color:#0000ff;">New</span> DataSet()</span></span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:12pt;"><span style="font-family:Times New Roman;"><span>        </span>adapter.Fill(ds, <span style="color:#a31515;">&#8220;name of function here&#8221;</span>)</span></span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:12pt;"><span style="font-family:Times New Roman;"><span>        </span>conn.Close()</span></span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:12pt;"><span style="font-family:Times New Roman;"><span>        </span><span style="color:#0000ff;">Return</span> ds</span></span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:12pt;"><span style="font-family:Times New Roman;"><span>    </span><span style="color:#0000ff;">End</span> <span style="color:#0000ff;">Function</span></span></span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:12pt;color:#0000ff;"><span style="font-family:Times New Roman;"> </span></span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:12pt;font-family:Arial;">You will notice that the SqlConnection is referencing a named connection string:</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:12pt;font-family:Arial;"> </span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-family:Times New Roman;"><span style="font-size:12pt;color:#0000ff;">Dim</span><span style="font-size:12pt;"> conn <span style="color:#0000ff;">As</span> <span style="color:#0000ff;">New</span> SqlConnection(ConfigurationManager.ConnectionStrings(<span style="color:#a31515;">&#8220;DatabaseNameHere&#8221;</span>).ConnectionString)</span></span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:12pt;font-family:Arial;"> </span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:12pt;font-family:Arial;">This is referencing code from the web.config file.<span>  </span>The connection string there looks like so:</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:12pt;font-family:Arial;"> </span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-family:Times New Roman;"><span style="font-size:12pt;color:#0000ff;">……&lt;</span><span style="font-size:12pt;color:#a31515;">configuration</span><span style="font-size:12pt;color:#0000ff;">&gt;</span></span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-family:Times New Roman;"><span style="font-size:12pt;color:#0000ff;"><span>            </span>&lt;</span><span style="font-size:12pt;color:#a31515;">appSettings</span><span style="font-size:12pt;color:#0000ff;">/&gt;</span></span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-family:Times New Roman;"><span style="font-size:12pt;color:#0000ff;"><span>            </span>&lt;</span><span style="font-size:12pt;color:#a31515;">connectionStrings</span><span style="font-size:12pt;color:#0000ff;">&gt;</span></span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-family:Times New Roman;"><span style="font-size:12pt;color:#0000ff;"><span>                        </span>&lt;</span><span style="font-size:12pt;color:#a31515;">add</span><span style="font-size:12pt;color:#0000ff;"> </span><span style="font-size:12pt;color:#ff0000;">name</span><span style="font-size:12pt;color:#0000ff;">=</span><span style="font-size:12pt;">&#8220;<span style="color:#0000ff;">databaseName</span>&#8220;<span style="color:#0000ff;"> </span><span style="color:#ff0000;">connectionString</span><span style="color:#0000ff;">=</span>&#8220;<span style="color:#0000ff;">server=Servername&#8217;; Database=databaseName; uid=; pwd=;</span>&#8220;<span style="color:#0000ff;"> </span><span style="color:#ff0000;">providerName</span><span style="color:#0000ff;">=</span>&#8220;<span style="color:#0000ff;">System.Data.SqlClient</span>&#8220;<span style="color:#0000ff;">/&gt;</span></span></span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-family:Times New Roman;"><span style="font-size:12pt;color:#0000ff;"><span>            </span>&lt;/</span><span style="font-size:12pt;color:#a31515;">connectionStrings</span><span style="font-size:12pt;color:#0000ff;">&gt;</span></span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-family:Times New Roman;"><span style="font-size:12pt;color:#0000ff;"><span>            </span>&lt;</span><span style="font-size:12pt;color:#a31515;">system.web</span><span style="font-size:12pt;color:#0000ff;">&gt;……</span></span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:12pt;color:#0000ff;font-family:Arial;"> </span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:12pt;font-family:Arial;">Now to get back to the web service. You will notice that right before the function there is a line: </span><span style="font-family:Times New Roman;"><span style="font-size:12pt;">&lt;WebMethod()&gt; _</span></span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:12pt;font-family:Arial;">This attribute enables the web service method to communicate with we appications located at local or remote locations. </span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:12pt;font-family:Arial;"> </span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:12pt;font-family:Arial;">Something I failed to mention previously is that there is a web service attribute that can be set. The syntax is like so: </span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:12pt;font-family:Arial;"> </span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:12pt;"><span style="font-family:Times New Roman;">&lt;WebService(Namespace:=<span style="color:#a31515;">&#8220;http://servername&#8221;</span>)&gt; _</span></span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:12pt;font-family:Arial;"> </span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:12pt;font-family:Arial;">This will provide additional information about the webservices, such as information about the functionality of the web service itself. </span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:12pt;font-family:Arial;"> </span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:12pt;font-family:Arial;">All we are doing in this web service is creating a dataset to be consumed by anyone who wants to use it. </span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:12pt;font-family:Arial;"> </span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:12pt;font-family:Arial;">To test the web service, all you have to do is right click on the service.asmx file and view in browser. If it works you will see the function name that you can click and then the next page allows you to invoke the function. The reuslt of clicking on invoke is a new page filled with XML data. If you see this, you have accomplished creatign a web service. <span> </span>You can create a web service to do anything you want it to do.<span>  </span>Just keep in mind that the key is reusablity. </span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:12pt;font-family:Arial;"> </span></p>
<p><span style="font-size:12pt;font-family:Arial;">In the next post, we will look at how to actually consume a web service in an appication and how to display the results of a web service.</span></p>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/aspnetteam.wordpress.com/25/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/aspnetteam.wordpress.com/25/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/aspnetteam.wordpress.com/25/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/aspnetteam.wordpress.com/25/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/aspnetteam.wordpress.com/25/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/aspnetteam.wordpress.com/25/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/aspnetteam.wordpress.com/25/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/aspnetteam.wordpress.com/25/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/aspnetteam.wordpress.com/25/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/aspnetteam.wordpress.com/25/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/aspnetteam.wordpress.com/25/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/aspnetteam.wordpress.com/25/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=aspnetteam.wordpress.com&blog=4774049&post=25&subd=aspnetteam&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://aspnetteam.wordpress.com/2008/09/11/using-web-services-how-to-create/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/e7de40145b3f1678a34b54c67d2c8e44?s=96&#38;d=wavatar&#38;r=G" medium="image">
			<media:title type="html">Frank</media:title>
		</media:content>
	</item>
	</channel>
</rss>