0

I have a web service and a custom logging service class. The logging class has a feature that update or remove itself according to the feature events (Activated=SPService.Update, Deactivating=SPService.Delete).

Can I add or remove the web service as the feature activate/deactivate ?

4
  • Simply check if the feature is activated in the WS's methods...
    – Steve B
    Commented Apr 10, 2013 at 15:34
  • This is a farm feature. Do I need the url of the centeral admin ?
    – user16261
    Commented Apr 10, 2013 at 15:42
  • You can check in SPCOntext.Current.Site.Farm.Features if I'm rigth. Iterate through this collection to find your feature ID. If not found, the feature is not activated.
    – Steve B
    Commented Apr 10, 2013 at 16:00
  • SPContext.Current.Site.WebApplication.WebService.Features[new Guid(LoggingFeatureId)]
    – user16261
    Commented Apr 10, 2013 at 18:45

2 Answers 2

1

Adding and removing webservice is not recommended and i don’t think its possible! You have the files in the ISAPI folder as DrFeelgood noted! in the ISAPI contains the wsdl and disco files.

But.... a big but.. you also need the webservice in the GAC folder (assembly). That means if you want to change the webservice to contain methods/remove than you would need to ammend the dll.

That moves me to the project, in your project when you reference to the webservice you would need to update it every time you add/remove.

So short answer is no, well not that i know of ;)

as stated by DrFeelgood, you need to add your dll to GAC, add disco and wsdl to ISAPI folder for discovery (_VTI_Bin) add web reference to your project and use the method that you require accordingly when activating/deactivating!

Is there any reason why you want to do it that way?

EDIT

Ok that makes sense!

in your method within the webservice you need to check for the feature and if its active or deactive, if active (true) carry on and return the result else return false if feature is deactive!

This is to check if the feature is active!

public static myCustomWebservicemethod()
{

     string guidStringFeature = "545646-56454-54665-56464";
     Guid guid = new Guid( guidStringFeature);
     using(SPSite site = new SPSite("url"))
     {
     if(IsFeatureActivated(site ,guid) == true)
     {
          //carry on with the webservice and return the value
          return true;
     }
     }

     //if its deactive than return false (nothing ;))
     return false;
}

public static bool IsFeatureActivated(this SPSite site, Guid featureId)    
{         
    return site.WebApplication.WebService.Fteaures[featureID] != null;    
}     

http://blogs.edwardwilde.com/2009/12/17/programmatically-determine-is-a-feature-is-activated-or-even-installed/

This method is better and less hassle / a method that i would recommend!

5
  • The webservice is using the logging class so if the logging feature is deactivated, the webservice should not work or should uninstall itself.
    – user16261
    Commented Apr 10, 2013 at 15:26
  • ammended my answer
    – Ali Jafer
    Commented Apr 10, 2013 at 15:48
  • Thanks. The feature is a farm feature. How can I get the web ?
    – user16261
    Commented Apr 10, 2013 at 15:56
  • remove spweb for SPSite Site, in the webservice you create and new site object and pass the site object to the method! in the method its site.WebApplication.WebService.Fteaures[featureID] != null
    – Ali Jafer
    Commented Apr 10, 2013 at 16:05
  • Thanks, ali... That was the solution: SPContext.Current.Site.WebApplication.WebService.Features[new Guid(LoggingFeatureId)]
    – user16261
    Commented Apr 10, 2013 at 18:29
0

What version of SharePoint are you using? I may have some old solutions that I deployed that were SharePoint Web Services I can use as reference to try to help. From what I recall with SharePoint 2010, all you do is deploy it to the ISAPI folder and you should be able to call it in your code.

2
  • We need support for all version (from 2007...)
    – user16261
    Commented Apr 10, 2013 at 15:27
  • I'm confused. Are you going to deploy the same service to different SharePoint installations? If that's the case why don't you host the web service outside of SharePoint to begin with, and make it an app on your IIS server?
    – EHorodyski
    Commented Apr 10, 2013 at 17:32

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.