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 been developing on SP 2010 for a while now. Mostly I have been working with the Client Object Model.

Though I am at a point where I need to read out the UserProfiles from inside SharePoint.

I see no other way to do this than to make a custom WCFService and deploy it to SharePoint.

So that is what I did. I made an "Empty SharePoint Project" and added the mapped "ISAPI" folder.

The code from the WCF Service:

public string GetUserByName(string _name)
    {
        string server = "http://esddev72";
        UserProfileManager profileManager;
        string s = "";
        string u = "";
        SPSecurity.RunWithElevatedPrivileges(delegate
        {
             using (SPSite site = new SPSite(server))
             {
                 SPServiceContext context = SPServiceContext.GetContext(site);
                 profileManager = new UserProfileManager(context, true);
                 s += "AccountNames: ";
                 u += "firstNames: ";
                 foreach (UserProfile profile in profileManager)
                 {
                     if (profile["AccountName"] != null)
                     {
                         s += profile["AccountName"] + " - ";
                     }
                     if (profile["FirstName"] != null)
                     {
                     }
                 }

             }
        });
        return s;
    }

This service gives a TimeOut error... When I delete the following line the TimeOut is fixed

if (profile["FirstName"] != null)
                     {
                     }

So I can only read out the AccountName... Does anyone know a solution to this?

I've read things about putting the timeout times higher, but it didn't work for me... Or maybe I did someting wrong, so if you could explain that part as well ;)

Thanks !

share|improve this question
    
Frederik: I saw your moderator request and I just tweeted a link to this for you. Sorry I don't have any idea about the answer; hopefully someone else will. Also try the MSDN Forums if you don't get and answer here. –  Marc D Anderson May 12 '10 at 12:31
    
Thanks Marc. I would realy want to know what is going wrong. I needed it in a project but since it kept failing i replaced it with an asmx webservice. But still, it should have to be possible to get a wcf service to work i guess... –  Frederik Prijck May 26 '10 at 7:33

4 Answers 4

Try PropertyConstants.

http://www.sharemuch.com/2010/03/29/creating-new-sharepoint-2010-user-profiles-programatically/

http://msdn.microsoft.com/en-us/library/microsoft.office.server.userprofiles.userprofilemanager.aspx

share|improve this answer
    
Thanks for the response, but i have already tried PropertyConstants and it did not work... I'll say again: The code IS working when i run it through a console application. But i need to get the UserProfiles in Silverlight so i have to use a WCF Custom Service to fetch the UserProfiles. And its here that it is going wrong ... –  Frederik Prijck May 25 '10 at 10:33

Well at this moment i solved it by using .asmx webservices... But still no idea how to solve the WCF TimeOut tho...

share|improve this answer

Did you deploy the service in the recommended SharePoint way? i.e. write the code and deploy a .svc file that references that class but uses the out of the box SharePoint factory i.e:

<%@ ServiceHost Language="C#" Debug="true" Service="YOURCLASS, YOURASSEMBLY, Version=1.0.0.0, Culture=neutral, PublicKeyToken=TOKEN" Factory="System.ServiceModel.Activation.WebScriptServiceHostFactory" %>

Yould also decorate your service class wit the following attributes

[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Required)]
[ServiceBehavior(Namespace = "http://servicenamespace/", IncludeExceptionDetailInFaults=true)] // IncludeExceptionDetailInFaults not required of course
[BasicHttpBindingServiceMetadataExchangeEndpointAttribute]

By doing this the service will be running as if it were in SharePoint and you can even use SPCOntext.Current. Security is also automatically done because it will be run by SharePoint.

share|improve this answer
<basicHttpBinding>

<binding name="BasicHttpBinding_myWCF" receiveTimeout="00:20:00" openTimeout="00:20:00" closeTimeout="00:20:00"

sendTimeout="00:20:00" maxBufferSize="2147483647" maxReceivedMessageSize="2147483647">

<security mode="None" />

</binding>

and in the web.config of the WCF service:

<bindings>

<basicHttpBinding>

<binding name="Binding1" receiveTimeout="00:20:00" sendTimeout="00:20:00" openTimeout="00:20:00" closeTimeout="00:20:00"

maxBufferSize="2147483647" maxReceivedMessageSize="2147483647"/>

</basicHttpBinding>

</bindings>

the web service method still times out after 1 minute and raises an exception in the client.

Also the

<serviceHostingEnvironment aspNetCompatibilityEnabled="true" />
share|improve this answer
    
So you're suggesting the solution is to increase the timeout to be 20 minutes? –  Benny Skogberg Sep 5 at 12:24

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.