Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

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 ?

10'x...

share|improve this question
    
Simply check if the feature is activated in the WS's methods... –  Steve B Apr 10 '13 at 15:34
    
This is a farm feature. Do I need the url of the centeral admin ? –  user16261 Apr 10 '13 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 Apr 10 '13 at 16:00
    
SPContext.Current.Site.WebApplication.WebService.Features[new Guid(LoggingFeatureId)] –  user16261 Apr 10 '13 at 18:45
add comment

2 Answers

up vote 0 down vote accepted

adding and removing webservice is not recommended and i dont 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!

share|improve this answer
    
The webservice is using the logging class so if the logging feature is deactivated, the webservice should not work or should uninstall itself. –  user16261 Apr 10 '13 at 15:26
    
ammended my answer –  ali Sharepoint Apr 10 '13 at 15:48
    
Thanks. The feature is a farm feature. How can I get the web ? –  user16261 Apr 10 '13 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 Sharepoint Apr 10 '13 at 16:05
    
Thanks, ali... That was the solution: SPContext.Current.Site.WebApplication.WebService.Features[new Guid(LoggingFeatureId)] –  user16261 Apr 10 '13 at 18:29
add comment

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.

share|improve this answer
    
We need support for all version (from 2007...) –  user16261 Apr 10 '13 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 Apr 10 '13 at 17:32
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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