Last active
January 27, 2021 06:40
-
-
Save Gerhard-ZA/0902c102d21cfaacc6ef1e2391e50900 to your computer and use it in GitHub Desktop.
Update WebConfig Method
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public void updateWebConfig() | |
{ | |
var configuration = WebConfigurationManager.OpenWebConfiguration("~"); | |
ServiceModelSectionGroup secgroup = (ServiceModelSectionGroup)configuration.GetSectionGroup("system.serviceModel"); | |
bool hasBasicPartyService = false; | |
bool hasWsPartyService = false; | |
bool hasUpdate = false; | |
//Verify if the BasicHttpBinding element exist | |
foreach (BasicHttpBindingElement binding in secgroup.Bindings.BasicHttpBinding.Bindings) | |
{ | |
if (binding.Name == "BasicHttpBinding_PartyServ") | |
hasBasicPartyService = true; | |
} | |
//Verify if the WSHttpBinding element exist | |
foreach (BasicHttpBindingElement binding in secgroup.Bindings.BasicHttpBinding.Bindings) | |
{ | |
if (binding.Name == "WSHttpBinding_PartyServ") | |
hasWsPartyService = true; | |
} | |
//Basic Service | |
if (hasBasicPartyService == false) | |
{ | |
secgroup.Bindings.BasicHttpBinding.Bindings.Add(CreateBasicHttpBinding("BasicHttpBinding_PartyServ", | |
BasicHttpSecurityMode.Transport, HttpClientCredentialType.None)); | |
secgroup.Client.Endpoints.Add(CreateEndPoint("BasicHttpBinding_PartyServ", "https://ws.domain.com/Party/Service.svc", | |
"basicHttpBinding", "BasicHttpBinding_INPartyServ", "NewParty.ServiceRef")); | |
hasUpdate = true; | |
} | |
//WS Service | |
if (hasWsPartyService == false) | |
{ | |
secgroup.Bindings.WSHttpBinding.Bindings.Add(CreateWSHttpBinding("WSHttpBinding_PartyServ", | |
SecurityMode.Transport, HttpClientCredentialType.None)); | |
secgroup.Client.Endpoints.Add(CreateEndPoint("WSHttpBinding_PartyServ", "https://ws.domain.com/Party/Service2.svc", | |
"wsHttpBinding", "WSHttpBinding_PartyServ", "NewParty.ServiceRef2")); | |
hasUpdate = true; | |
} | |
if (hasUpdate == true) | |
{ | |
configuration.Save(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment