Recent Posts
- November 2014 (1)
- January 2014 (1)
- October 2013 (1)
- May 2013 (1)
- February 2013 (2)
- October 2012 (1)
- August 2012 (1)
- July 2012 (4)
- June 2012 (13)
Blog Stats
- 36,360 hits
Write your code smartly
DHCP is an automated method of assigning the addresses i.e IP addresses to the devices connected in a network which decreases the overhead of the manual work done by the network administrator. It has a central database of devices attached to the network and helps to avoid replica of the resource assignment to the devices.
The hosts that does not use DHCP for address assigning can still use DHCP to obtain other configuration information.
It is very useful even in small networks as it can easily add new machines to the network. When the computer or device tries to attach to a network the DHCP sends a query to the DHCP server to get the information of the client system such as default gateway, domain name, name servers. After receiving the valid information DHCP assigns the computer a address and the time it will be valid till including subnet mask.
It uses two ports , port 67 to send data to servers and port 68 to receive data to client. Its communication is connectionless in nature.
Here I am going to guide you about how to create web service in .net framework 3.5. You can create this web service in Visual Studio by selecting new project > and target framework 3.5 and select web service from the list. This web service will retrieve data from SQL server database and response a XML version of it.
Here is the web.config connection string:
Windows Authentication:
<appSettings> ConnectionString(name of your choice)" value="Data Source=server name;Initial Catalog=DB name;Integrated Security=SSPI;"/> </appSettings>
Now, open your “service1.asmx.cs” file and put the following code inside the namespace.
[Web Service(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
// To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.
// [System.Web.Script.Services.ScriptService]
public class Service1 : System.Web.Services.WebService
{
string dbConnString = System.Configuration.ConfigurationManager.AppSettings["ConnectionString"];
[WebMethod]
public XmlDocument getDataXML(string strQuery, string strRootNode, string strItemNode)
{
// Create vars out of connection string and query string
string dbConn = dbConnString;
string dbQuery = strQuery;
// Connect to the database and run the query
SqlConnection conn = new SqlConnection(dbConn);
SqlCommand cmd = new SqlCommand(dbQuery, conn);
SqlDataAdapter da = new SqlDataAdapter();
DataSet ds = new DataSet();
ds.DataSetName = strRootNode;
da.SelectCommand = cmd;
da.Fill(ds, strItemNode);
// Return the data as XML
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.LoadXml(ds.GetXml());
return xmlDoc;
}
}
To check, run the code and click the link getDataXML and provide the query you want to execute and tags you want to receive the data in and click invoke.
For example:
strQuery= select * from Users; strRootNode= Node strItemNode= Record
Output:
<Node> <Record> <LoginId>7</LoginId> <LoginName>Administrator</LoginName> <Email>admin@admin.com</Email> <Username>admin</Username> <Password>admin</Password> <Rights>1</Rights> <ModifiedDate>2008-06-15T00:00:00+05:00</ModifiedDate> </Record> <Record> <LoginId>9</LoginId> <LoginName>Jibran</LoginName> <Email>ji_jibran1990@hotmail.com</Email> <Username>Jibs</Username> <Password>abc</Password> <Rights>1</Rights> <ModifiedDate>2008-06-15T00:00:00+05:00</ModifiedDate> </Record> </Node>
I welcome you all to my blog. I love sharing my experiences through writing post here so I will try my best to share my knowledge frequently. You can write me through any medium from about page for any correction or just simply write a comment below respective post.