How To Transfer App.Config ApplicationSettings to Web.config

Add Web Reference from a class library for .Net 2.0

If you still use .Net framework 2.0, the way to reference a web service to your project is to add a Web Reference.
What if you want to add the web reference from a class library project? This will result to Visual Studio automatically
adding an app.config to your project. The app.config will contain the configuration under applicationSettings of the newly added reference of the web service.

Add Web Reference - ApplicationSettings

Add Web Reference

The app.config will look like this for example.

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<sectionGroup name="applicationSettings" type="System.Configuration.ApplicationSettingsGroup, System,
Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" >
<section name="Noel.Sample.ServiceInterface.Properties.Settings"
type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral,
PublicKeyToken=b77a5c561934e089" requirePermission="false" />
</sectionGroup>
</configSections>
<applicationSettings>
<Noel.Sample.ServiceInterface.Properties.Settings>
<setting name="Noel_Sample_ServiceInterface_ServiceHello_Service"
serializeAs="String">
<value>http://localhost:59962/Service.asmx</value>
</setting>
</Noel.Sample.ServiceInterface.Properties.Settings>
</applicationSettings>
</configuration>

What if you want to use one config file?

Your main application is a web application and it has its own web.config file. What if you want to use and maintain one
config file? You don’t need to point the app.config section from your web.config file. You can move the section group and
the section of the web service from your app.config to your web.config.

Move app.config applicationSettings to Web.config

<configuration>
<configSections>
<!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework,
Version=5.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
<sectionGroup name="applicationSettings" type="System.Configuration.ApplicationSettingsGroup, System, Version=4.0.0.0,
Culture=neutral, PublicKeyToken=b77a5c561934e089" >
<section name="Noel.Sample.ServiceInterface.Properties.Settings"
type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral,
PublicKeyToken=b77a5c561934e089" requirePermission="false" />
</sectionGroup>
</configSections>
<applicationSettings>
<Noel.Sample.ServiceInterface.Properties.Settings>
<setting name="Noel_Sample_ServiceInterface_ServiceHello_Service"
serializeAs="String">
<value>http://localhost:59962/Service.asmx</value>
</setting>
</Noel.Sample.ServiceInterface.Properties.Settings>
</applicationSettings>
</configuration>

The section group can be added to the configSections. The applicationSettings can be added under the configuration section of the web.config.

Get value of service URL from Web.Config under applicationSettings

Under appSettings of a Web.config file usually you use for example ConfigurationManager.AppSettings[“WebServiceURL”] to get a value in the Web.config. But when the URL is under the applicationSettings in a Web.config this is how you can get the value of the URL.

public class ConfigHelper
{
public string GetUrl()
{
var section = (ClientSettingsSection)ConfigurationManager.
GetSection("applicationSettings/Noel.Sample.ServiceInterface.Properties.Settings");
var url = section.Settings.Get("Noel_Sample_ServiceInterface_ServiceHello_Service").Value.ValueXml.InnerText;
return url;
}

}

The last step is to remove the app.config from the class library. This is the case if the app.config was added to have the configuration of the web reference. In other cases where you need to the app.config, just remove the configSections and applicationSettings for the web service.

I spent some time looking for a way to make this work and not too much resource from web points to this approach. Hopefully it can help solving yours in less time. Thank you for this post from Stackoverflow on how solve this problem.

Comparing using CompareTo C# Method

 

A colleague asked me for a suggestion on the program module he is doing that involves determining if one value is “>” greater than, “=” equal or “<” less than another value. I first thought of a solution involving a stack but its too low level and involves much longer code. After some suggestions and trying to think of another way, he came across of a solution to use CompareTo C# method.

What is CompareTo C# Method?

First, MSDN defines IComparable as an interface that “Defines a generalized type-specific comparison method that a value type or class implements to order or sort its instances.” It has a method called CompareTo which as defined by MSDN “Compares the current instance with another object of the same type and returns an integer that indicates whether the current instance precedes, follows, or occurs in the same position in the sort order as the other object.”

The CompareTo method is available on all objects as long as the objects has the same type. See the sample code below for comparing value types integer and a string type.

CsharpCompareTo

 

The Return Value of CompareTo

The CompareTo method has a return value of int. The integer value return will be one of the values less than 0, 0 or greater than zero as what is shown below.

CompareToReturnValues

 

Nullable Types Does Not Implement CompareTo

Take note that Nullable types like int? short for Nullable<int> does not implement the CompareTo method. It will not even compile since the method is not implemented.

CompareToNullable

This blog post will serve as a quick reference for me whenever there is a need for me to use sorting or comparison of data when programming. I hope it will serve the same for you.

 

 

Changing My DNS Provider to DNSimple – What DNS Record?

 

Problem with my current DNS provider – GoDaddy.com

I made a blog post two years ago on how I setup this site File -> New Blog Project. As of this writing, this site is using WordPress and GoDaddy.com for web hosting and DNS. Lately, I have noticed that sometimes I cannot access my website noelarlante.com and its admin page. Its maybe my internet provider is slow? or my internet is totally down? A quick access to Google proves otherwise.

I did a trace route to noelarlante.com and to my surprise I got timeouts (* * *) on after a certain ip address. My main hosting ip address is working which means the domain name resolution is not working due to the time out.

Traceroute has started…

traceroute to noelarlante.com (203.124.115.1), 64 hops max, 72 byte packets

 1  192.168.11.1 (192.168.11.1)  1.474 ms  1.515 ms  1.011 ms

 2  192.168.254.254 (192.168.254.254)  1.785 ms  1.685 ms  1.584 ms

 3  180.191.75.1 (180.191.75.1)  17.557 ms  17.863 ms  17.545 ms

 4  10.109.9.65 (10.109.9.65)  17.431 ms  21.192 ms  17.735 ms

 5  120.28.0.193 (120.28.0.193)  18.478 ms  23.496 ms  17.978 ms

 6  120.28.10.93 (120.28.10.93)  18.563 ms  21.173 ms  18.075 ms

 7  120.28.4.94 (120.28.4.94)  49.112 ms  52.709 ms  48.848 ms

 8  203.169.57.37 (203.169.57.37)  48.052 ms  48.126 ms  46.980 ms

 9  xe-5-2-0-xcr1.sgs.cw.net (195.2.10.214)  87.515 ms  86.563 ms  86.042 ms

10  ae0-xcr1.sng.cw.net (195.2.10.149)  77.411 ms  78.375 ms  76.861 ms

11  * * *

12  * * *

13  * * *

14  * * *

15  * * *

16  * * *

17  * * *

18  * * *

19  * * *

20  * * *

 

Although I still have two more years with GoDaddy DNS, but I have decided to try and use DNSimple.

Moving My DNS service to DNSimple

DNSimple Support page provides a topic on How Transfer Domain Without a Downtime,  which is the perfect information I need to prevent downtime for my website. Transferring a domain to DNSimple was painless. Its just that I missed a step that ended my site to be down for a day – more on that next.

DNS  DNSimpleDomainAddTransfer

Steps on transferring a domain without a downtime

Here are the steps on how to transfer a domain to DNSimple without a downtime based from the Support page of DNSimple. I’ve highlighted the one step I’ve missed.

After doing the *ALL* the steps I thought that I will just need to wait for the DNS to propagate to all servers and then thats it, transfer done. But after awhile I tried to hit noelarlante.com but I got a “Host Unreachable” error on my browser. Something is wrong and I soon figured that there is a disconnect from my DNS to my hosting server.

Problem Solved – I Missed Adding DNS Records

According to Wiki – DNS records or resource records (RR) is the basic data element in the domain name system.
There are many record types that you can use. DNSimple support has the information about each of them – http://support.dnsimple.com/categories/dns/

 I only care about A, CNAME

A – An A record is an Address. This is the record that maps the address i.e. noelarlante.com to my hosting site

CNAME – CNAME is short for Canonical Name. It is the record that maps an alias to an address. The “www” is considered an alias or an address going to noelarlante.com. If no CNAME with “www” is added to the DNS record, www.noelarlante.com will not be resolved to noelarlante.com.
DNS  DNSimpleAddAliasRecord

DNS  DNSimpleDNSRecords

I got my website a new DNS service provider and so far I’m happy with the response time when I visit my site. This is not in anyway a paid advertisement for DNSimple, I’m just sharing my experience and hope others can find this post and not forget that DNS record step.