I am dynamically adding bindings in web.config
. But I don't know how to remove it
Here is complete code
public override void FeatureActivated(SPFeatureReceiverProperties properties)
{
SPFarm farm = SPFarm.Local;
webApp = properties.Feature.Parent as SPWebApplication;
string endpointadr = "https://testserver/myservice.svc"
string bindings = @"
<bindings>
<wsHttpBinding>
<binding name=""WSHttpBinding_IAuthenticationService"">
<security mode=""TransportWithMessageCredential"">
<transport clientCredentialType=""None"" />
<message clientCredentialType=""UserName"" establishSecurityContext=""false"" />
</security>
</binding>
</wsHttpBinding>
</bindings>
<client>
<endpoint address="""+endpointadr+ @""" binding=""wsHttpBinding"" bindingConfiguration=""WSHttpBinding_IAuthenticationService""
contract=""testService.IMyService"" name=""WSHttpBinding_IAuthenticationService"" />
</client>";
webApp = properties.Feature.Parent as SPWebApplication;
RemoveModifications();
webApp.WebConfigModifications.Add(AddBindings(bindings));
webApp.Update();
webApp.Farm.Services.GetValue<SPWebService>().ApplyWebConfigModifications();
}
private SPWebConfigModification AddBindings(string bindingString)
{
var modification = new SPWebConfigModification("bindings", "configuration/system.serviceModel");
modification.Value = bindingString;
//modification.Sequence = 0;
modification.Type = SPWebConfigModification.SPWebConfigModificationType.EnsureChildNode;
modification.Owner = Owner;
return modification;
}
private string Owner
{
get { return "MyTestPage" + webApp.Id; }
}
private void RemoveModifications()
{
var mods = from m in webApp.WebConfigModifications.AsEnumerable() where m.Owner == Owner select m;
while (mods.Count() != 0)
{
webApp.WebConfigModifications.Remove(mods.First());
}
}
It's not removing anything when I call removeModification
Update 1 In web.config its adding like this
<client>
<endpoint address="https://testserver/myservice.svc" binding="wsHttpBinding" bindingConfiguration="WSHttpBinding_IAuthenticationService" contract="Myservice.IMyService" name="WSHttpBinding_IAuthenticationService" />
</client>
<bindings>
<wsHttpBinding>
<binding name="WSHttpBinding_IAuthenticationService">
<security mode="TransportWithMessageCredential">
<transport clientCredentialType="None" />
<message clientCredentialType="UserName" establishSecurityContext="false" />
</security>
</binding>
</wsHttpBinding>
</bindings>
<client>
<endpoint address="https://testserver/myservice.svc" binding="wsHttpBinding" bindingConfiguration="WSHttpBinding_IAuthenticationService" contract="MyService.IMyService" name="WSHttpBinding_IAuthenticationService" />
</client>
Not sure why its adding client tag twice