3

I just developed a custom WebService mainly for the purpose of integration with 3rd party application based on Oracle Database. My project looks like this. enter image description here

This service has some procedures which requires database connectivity like Oracle database connection string and SQL Server database connection string. Now how can I add web.config and deploy so my methods can pick those values from appsettings of webconfig and consume. Or is there any other way where we can store.

3 Answers 3

0

After reading your comments user342944,

Why don't you just create a simple XML file and then read it using XmlTextReader for getting credentials instead of creating a web.config for your web services project, as if you make any changes to your web.config, you will must have to re-compile it.

As far as I know you don't need to recompile your project after changing web.config if its directly getting read by IIS manager for a web application's settings.

Note

I recommended above way of solving your problem after reading your comments and I personally believe it might not be the best practice.

0
3

You can add a feature receiver to a feature in your project to provision and retract (on feature activation and deactivation respectively) the web.config modifications that you need to all WFEs in the farm by using the SPWebConfigModification class in the Microsoft.SharePoint.Administration namespace.

This class works with the SharePoint Object Model to make the changes that you need to implement, but also tracks those changes while providing you the ability to revert without having to worry about what the previous web.config settings were.

In your case, the revision tracking may not be as important to you as you're likely only adding new nodes, rather than changing existent values, but you can mark your modifications as uniquely relating to this project via the Owner property of the class.

Something like:

public override void FeatureActivated(SPFeatureReceiverProperties properties)
{
    SPWebAppliation webApplication = (properties.Feature.Parent as SPWebApplication);

    SPWebConfigModification webConfigModification = new SPWebConfigModification();
    webConfigModification.Name = "add[@name=\"OraSPDataXchange\"]";
    webConfigModification.Path = "configuration/connectionStrings";
    webConfigModification.Owner = "OraSPDataXchange";
    webConfigModification.Sequence = 0;
    webConfigModification.Type = SPWebConfigModification.SPWebConfigModificationType.EnsureChildNode;
    webConfigModification.Value = "<add name=\"OraSPDataXchange\" providerName=\"System.Data.SqlClient\" connectionString=\"YourString\" />";

    webApplication.WebConfigModifications.Add(webConfigModification);
    webApplication.Update();
    webApplication.Farm.Services.GetValue<SPWebService>().ApplyWebConfigModifications();
}

Rinse and repeat.

Other links that may be beneficial:

Web.config modifications with a SharePoint feature

SPWebConfigModification – A closer look

3
  • rjcup thanks for the detailed answer. Well its in Layout but I am generating disco and WSDL files by disco portal.mydomain.com/_layouts/CustomWS/OraSPDataXchange.asmx ..and then I make required changes in both files and change the path like <% SPHttpUtility.AddQuote(SPHttpUtility.HtmlEncode(spWeb.Url + "/_vti_bin/OraSPDataXchange.asmx?wsdl"), Response.Output); %>.......and simply placing asmx, disco and wsdl files into _vti_bin...dont know if its a right procedure or not. so in this context is there any other easy way to pick user and password for connections strings?
    – user342944
    Mar 17, 2013 at 6:02
  • 1
    rcjup..i want to add, update and read key values from web.config..i work for a bank where information security policy is very strong. they change passwords periodically so need an easy way to maintain userids and passwords..it looks like for a change they need to talk to developer and developer would make change in the feature and then deploy again..it will be a pain..
    – user342944
    Mar 17, 2013 at 6:42
  • So why not set up a script to automate this? This would help to prevent some amount of user error by ensuring all changes are made to each server. While I agree that your way is quicker, the quickest way to do something is not always the right way. Mar 20, 2013 at 17:20
2

A web.config in the same folder as the web service (asmx, svc, etc) will be scoped only within that folder, so you can have settings specific to things running within that directory.

I've did this a few times, with no need to use _vti_bin. Just keep the service endpoint (.svc, .asmx, etc.) file in the Layouts directory (in the project's folder).

This saves many of the headaches of using WebConfigModification classes - which are fraught with so many problems that nearly everyone I know has found it cheaper and more maintainable to have deployment instructions to manually edit webapp config files - If you just use the _LAYOUTS directory subfolder for your service + it's own web.config, you won't have any of this pain.

3
  • I agree with you that the class is a huge pain to work with in 2010. I hope 2013 is better. Haven't tried it yet. What are the repercussions of not using the _vti_bin directory? Does this article have any merit? jamestsai.net/Blog/post/… Mar 16, 2013 at 23:52
  • I'm really just curious because I've never deployed an .asmx service to the _layouts directory, always just to _vti_bin. Mar 17, 2013 at 0:10
  • James my project is in a very critical stage and I have less time and all my lists are one one place like portal.mydomain/EformsCenter ..this is the place where all my lists are talking in and out with Oracle. So in this case don't need vti_bin to know the exact path. Now can I place it in layouts and create web.config like normal .net applications and read keys? i want something easy to modify.
    – user342944
    Mar 17, 2013 at 6:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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