Through various sources on the web, I've seen simple ways to modify web.config from a SharePoint feature. However they are typically one liners. But if I need to add a WCF Binding such as this:

    <binding name="thisName">
      <security mode="None" />
  <endpoint address="http://thisserver" binding="wsHttpBinding" bindingConfiguration="thisConfig" contract="thisContract" name="thisName" />

Not sure what would be the easiest way to do such a bulk insert. It would be under and most likely the entire block would have to be inserted as typically WCF bindings aren't used in web.config's.

1 Answer 1


Use the C# following code to modify the web.config:

string content;
string WebServiceServer = "example.com"; // <=== your host-name here
using (TextReader tr = File.OpenText(bindingFilePath))
    content = String.Format(tr.ReadToEnd(), WebServiceServer);

SPWebConfigModification modification = new SPWebConfigModification("system.serviceModel", "configuration");
modification.Value = content;
modification.Sequence = 0;
modification.Type =SPWebConfigModification.SPWebConfigModificationType.EnsureChildNode;
modification.Owner = OWNER_CONSTANT;


I spent some time figuring it out. Hope this will help someone.https://stackoverflow.com/questions/3147439/adding-web-service-bindings-into-sharepoint-web-config-using-spwebconfigmodifica


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.