Purpose
The purpose of this tutorial is to show some of the things you can set or retrieve in an app.config file and a web.config file.
App.Config - Retrieve Endpoint Address:
This is an example of what may be present in the app.config
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="webSvcEndPoint">
<security mode="Transport">
<transport clientCredentialType="Windows" />
</security>
</binding>
</basicHttpBinding>
<customBinding>
<binding name="webSvcEndPoint">
<textMessageEncoding messageVersion="Soap12" />
<httpTransport />
</binding>
</customBinding>
</bindings>
<client>
<endpoint address="https://some-service-site.com/web-service.asmx" binding="basicHttpBinding" bindingConfiguration="webSvcEndPoint" contract="webSvcEndPoint" name="webSvcEndPoint" />
</client>
</system.serviceModel>
App.Config - Retrieve Endpoint Address:
This is the code which gets the address
using System.ServiceModel.Configuration;
var enpointAddress = "";
var serviceModel = ServiceModelSectionGroup.GetSectionGroup(ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None));
var endpoints = serviceModel.Client.Endpoints;
foreach (ChannelEndpointElement e in endpoints) {
if (e.Name == "webSvcEndPoint") { endpointAddress = e.Address; }
}
/* At this point endpointAddress = "https://some-service-site.com/web-service.asmx"; */
Web.Config - Force HTTPS:
<system.webServer>
<rewrite>
<rules>
<rule name="ForceSSL" patternSyntax="Wildcard" stopProcessing="true">
<match url="*" />
<conditions>
<add input="{HTTPS}" pattern="off" />
</conditions>
<action type="Redirect" url="https://{HTTP_HOST}/{R:1}" redirectType="Permanent" />
</rule>
</rules>
</rewrite>
</system.webServer>
BONUS! Simple code block to use a message box (usually for debugging/troubleshooting):
string message = "some message";
string caption = "Debug Info";
var boxmaker = MessageBox.Show(message, caption, MessageBoxButtons.YesNo, MessageBoxIcon.Question);