I'm exploring the possibility of deploying WCF services to a SharePoint Farm/WebApplication/Site/Web via a SharePoint feature without using the SPWebConfigModification class or manually editing web.config. The Gille virtual path fix has already been applied so it doesn't factor into this. The furthest I've been able to get thus far is creating a custom ServiceHostFactory class which I'm referencing inside the .svc file like so:
<%# ServiceHost Language="C#" Debug="true" Service="Company.Namespace.ServiceClass" Factory="Company.Namespace.CustomServiceHostFactory" %>
<%# Assembly Name="Company.WCFCustomLib, Version=1.0.0.0, Culture=neutral, PublicKeyToken=0000000000000000" %>
I'm overriding ServiceHost CreateServiceHost(Type serviceType, Uri[] baseAddresses) inside my custom service host factory and applying the various binding/endpoint configuration inside. But the problem I'm running into is that the method isn't even being called when I query the .svc file in my web browser. I was under the impression that IIS will try to create a ServiceHost using the ServiceHostFactory I specified as soon as I call the .svc in my web browser. Am I totally mistaken? Has anybody ever attempted to do something like this before? If so, is there something I'm missing? Is it possible to set up the ServiceHost completely programmatically or do I still have to mess around with <system.serviceModel> tags inside web.config?
You can do what you want, and get WCF to read configuration from where-ever you like. I built this once, to allow each WCF service to read from its own config file. Good for testing and independent deployment. The technique involves overriding the ServiceHost.ApplyConfiguration method.
This blog post has some additional details and full source code.
Another approach of general interest might be to let the WCF service read its config from a centralized store somewhere - a database, a remote file server, etc. You could use the same basic CustomServiceHost, and just modify one method to load from a database, or whatever.
ps: the reason IIS is disappearing is, I suspect, you have an exception occurring in the WCF ServiceHost.
Probably not the answer you are looking for, but I have gone into a bit of detail on how to have WCF-like capability in SharePoint on the SharePoint Depth wiki here. I go into the most detail on using a HttpHandler in lieu of WCF, but I also have some links for full-blown WCF in SharePoint.
In the HttpHandler approach you do not need to modify the root web.config file, but you do need to add a web.config file in your own folder.
I hope this provides some insight.
Related
I'm exposing a web service in a SharePoint site e.g. http://server/_vti_bin/subdir/mywebservice.asmx.
In the web service method, SPContext.Current appears to be null.
(Interestingly, I'm looking at an example in Chapter 5 of Inside Windows SharePoint Services 3.0 and they use SPContext.Current inside a web service!)
Any idea what am I missing? Thanks in advance.
The only times when I saw a SPContext.Current = null was when the webservice was called at a virtual location that didn't exist (i.e. an URL that was only half correct).
In your problem specification, you mention "_vti_bin/subdir". I have not seen this subdir construct in a WebService hosted within SharePoint yet (disclaimer: my knowledge is limited to 2 or 3 working implementations of a custom webservices within SharePoint)
Normally, you'd
Put the asmx straight into the ISAPI folder of the 12 hive. This will map onto _vti_bin.
Put the assembly, if any, in the GAC (or in the website bin, but I'd suggest using the GAC until you get the basics up and running)
Do stuff for discovery if you really need to, but for testing this shouldn't be necessary
It might not be related at all, but I'd still try to get things working from the _vti_bin first, then try and mess with subfolders. SharePoint's url virtualization can be painful.
Is it possible that your subdirectory is set up as a web application and is therefore operating in a different context?
How are you calling the webservice? Is this an ajax call from javascript/jquery? If yes, have you added the ScriptService attribute on the webservice class?
[System.Web.Scripts.Services.ScriptService]
public class SimpleWebService : System.Web.Services.WebService
{
...
...
}
According to MSDN, for deploying custom web service, we need to create *wsdl.aspx and *disco.aspx files, and put them with .asmx together under _vti_bin folder (C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\isapi). And put the dll under bin folder of the root of sharepoint virtual directory. It works correctly for me.
However, i also found that if i put .asmx file under the root virtual directory without creating those *wsdl.aspx and *disco.aspx files. It can work as well and much easier than the above way. So i'm wondering what's the potential issues in this way?
Without the WSDL and DISCO files, folks' web service clients/consumers may have a hard time "discovering" your service's contract. If that's not a concern for you, don't worry about it.
I have created several web services in SharePoint 2007 that were simply deployed as http://.../_layouts/mySubFolder/service.asmx. It works! For SharePoint it does not matter whether the presentation layer is HTML or XML for a web service (in both cases security must be applied, can be addressed both as http://server/_layouts/mySubFolder/service.asmx and http://server/sites/subsite/_layouts/mySubFolder/service.asmx
Things that are wrong thing about it
the word "layouts" implies "something to do with how it looks like".. which is not the case when we speak about web services
when migrating to SPS2010 where WCF services come into play, it will be different. However, I have not yet played with SPS2010 and do not yet know, how different. (Somehting about it here - http://blog.mastykarz.nl/wcf-sharepoint-context/)
Quite an old post but just thought i'd add to this as I don't believe the responses to date give the relevant detail on why SharePoint is setup this way.
The reason why you deploy webservices to ISAPI\vti_bin for SharePoint is because there are specific modifications made for requests to this folder to allow SharePoint to build an accurate discovery and WSDL file for the service based on the current virtual path of the service, not the path in the IIS site.
More specifically wsdisco.aspx and wswsdl.aspx handle requests to this virtual directory and will call the relevant disco.aspx and wsdl.aspx to generate the discovery xml or wsdl xml correctly based on the current SharePoint url.
If you add a service reference to your project for http://sharepointsite.com/sitecol/subsite/_vti_bin/lists.asmx the context for requests made on that url will be relevant to /sitecol/subsite as you would expect.
However if you add a service reference to http://sharepointsite.com/sitecol/subsite/_layouts/MyCustSvc.asmx the context will be fixed to http://sharepointsite.com/ because the default wsdl generator for ASP.NET is not aware of the SharePoint virtual paths. In which case calls to SPContext in the service will not work as expected.
There is an excellent post here with examples explaining this:
Where do you deploy custom SharePoint web service files to?
I've been trying to follow the information from:
Long URL clipped to stop breaking the page
and
http://msdn.microsoft.com/en-us/library/ms415817.aspx
Which more or less have the same instructions. I've been copying the .dll file from the build over to the BIN directory of the Sharepoint site.
When I click the Web Part Gallery and hit new, both articles say that the web part should show up in the list.
I have tried every possible way that I can think, but my web part will not show up in that list. Is there a step that I missed somewhere? Are there permissions that I should be thinking about? How exactly does Sharepoint recognize that there is a new web part. Is it simply from having the assembly placed in the BIN directory, or is it from adding the control in the safe list of web.config?
I've added it to the safe controls list. I've tried every different combination that I could think of, but nothing has worked.
Do I need to rename the .DLL assembly to something else?
For the life of me I cannot figure this out.
I believe the minimum you need to have a WP show up in the "New" Part of the webPart Catalog, you need the dll in the "bin" folder (bin in the web dir, not the 12 hive :)) or in the GAC and a safe control entry. I would verify the Safe control entry:
Assembly = name of dll
NameSpace = well... The NameSpace where your WebPart class resides
TypeName = the name of your webPart class
You can wildcard the NameSpace and TypeName just to be sure you are getting there:
... Namespace="*" TypeName="*" ...
I would also recommend signing the assembly and putting in a PublicKeyToken=...
Also, try setting the trust level to WSS_Medium or Full.
If this doesn't work, you can try adding a .webpart file to the wpCatalog folder in your web dir.
Edit: Clarification
This has to be a mismatch between your assembly and what has been entered into web.config for the safecontrol entry.
The safecontrol entry is case sensitive - and the smallest of errors will stop is from showing on the 'New' listing of the web part gallery.
Also make sure you are editing the correct web.config! :-) Another common gotcha is that your web part class has to be public.
Hope this helps
Nick Swan
Have you tried using the WPPackager tool from Microsoft? I haven't touched SharePoint since v2003, and I know there was a handy tool for WP deployment for that platform. I'd offer a link to it, but 1) I can't remember its name, and 2) I'm not sure if it is a valid installation route for your version of SharePoint.
Wow, you have me stumped ... I would try deploying some other 3rd party "free" web parts manually and see if you can get those to show up. This site has a few:
http://www.sharepointblogs.com/mkruger/archive/2007/06/26/free-sharepoint-web-parts-3rd-party.aspx
Have you made sure that you set: [assembly: AllowPartiallyTrustedCallers]
in your AssemblyInfo file?
I am amazed no one else has chimed in on this. I guess next step would be to try to deploy it as a feature/solution.
Is this a simple hello world wp or are you doing something more?
To be honest, I am beginning to believe that it is your wss/moss configuration/settings that is hampering your efforts at the moment. Have you ever successfully deployed a WP to your farm? ... Is this a VPC dev farm or production?
I've been creating a few web parts over the past 2 weeks, but I have not used the "New Web Parts" section of the Web Part Gallery. Instead, I create a .dwp file (e.g. MyWebPart.dwp), which is more or less an XML file describing the web part, and I manually import it into the gallery.
The format for my .dwp files generally looks like this:
<?xml version="1.0" encoding="utf-8"?>
<WebPart xmlns="http://schemas.microsoft.com/WebPart/v2" >
<Title>My Sample Web Part</Title>
<Description>This web part displays "Hello World" on the page.</Description>
<Assembly>My.Assembly, Version=1.0.0.0, Culture=neutral, PublicKeyToken=3ed03eac7f647a61</Assembly>
<TypeName>My.Assembly.MyWebPartClassName</TypeName>
<!-- Specify initial values for any additional base class or custom properties here. -->
</WebPart>
This of course assumes that you've added this assembly as a "Safe Control". After you compile your assembly and move it into the bin/GAC for your SharePoint machine, go back to the web part gallery, click "Upload", and upload your .dwp file. You'll have to specify a few properties after uploading it.
Assuming your web part exists in your .dll, then you should see it added to the gallery list, and you can preview it or add it to a page at that point.
We have a SharePoint farm with multiple WFEs. A new application requires us to write some custom code to the web.config during deployment. What is the best way modify the the web.config file during deployment, ensuring that each WFE in the farm get updated?
I'm assuming you'll be deploying your code via a WSP; if not, using a tool like WSPBuilder is a great starting place that allows you to get rolling without forcing you to learn all of the intricate details of solution package construction.
You should leverage the SPWebConfigModification type from within a custom SPFeatureReceiver. Normally, the FeatureActivated method of the SPFeatureReceiver would be coded to write the changes out to the web.config files impacted by your activation. Those same changes would then be retracted in the FeatureDeactivating method.
The nice thing about the SPWebConfigModification type is that SharePoint takes care of determining which web.config files should be modified -- across servers and across extended web apps.
I hope this helps!
As part of your deployment, use the SPWebConfigModification class to add/remove entries from web.config. SharePoint will manage updating the WFEs for you if you use this.
A blog post entitled, Modify the web.config file in SharePoint using SPWebConfigModification, is a great summation of the gotchas involved and contains links to other helpful resources.
Using the SharePoint API, how can I modify an extended webapp web.config file?
I have to do some changes in this file to specify the connection string, membershipprovider, etc... for using Forms Authentication.
Currently, I can change the "master" webapplication web.config file, but not the extended one.
Edited
I'm using Sp 2007. I'm already using SPWebConfigModification class to modify the parent webapp. Thoses modifications are propagated to the extended webapp. I have to change ONLY the extended one. But I don't find the way to do it.
What I'm trying to achieve, is to program a little wizard that:
Shows a WebApp list so the user can select one
Extend that selected webapp to a different zone
Configure that extended zone to use Forms Authentication
Thanks
I got an answer form a blog.
In your case , you need to write a Web Application scoped feature which after you provision your site using your C# app, it is deployed to the newly-provisioned site and in the receiver of the feature you inject the required web.config settings because in that context configuration API is obtainable , but again bear the following in mind:
If you don’t use SPWebConfigModification class and either use ASP.NET 2.0 configuration API or your own mechanism , propagating changes across the farm is YOUR RESPONSIBILITY. If this happens on an standalone installation then you don;t need to be worried about this.
So it cannot be done externally. We have to do a feature in order to acheve this.
Thanks
Quick answer: look into the SPWebConfigModification class. I am assuming you're using SharePoint 2007. The best way to learn about this is to dig into open source projects:
Google code search: http://www.google.com/codesearch?q=spwebconfigmodification&hl=en&btnG=Search+Code
This project on CodePlex looks like it's one big SPWebConfigModification: http://www.codeplex.com/ajaxifymoss/Release/ProjectReleases.aspx?ReleaseId=13360