Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Impersonate core service in Tridion 2011 SP1 HR1

I am trying to impersonate the Core Service in Tridion 2011 SP1 HR1 and I get this error:

The message could not be processed because the action 'http://www.sdltridion.com/ContentManager/CoreService/2011/ISessionAwareCoreService/Impersonate' is invalid or unrecognized.

Why does this happen? I have to be blind to not see why it isn't working...

About the server: new installation of Tridion 2011 SP1 HR1

My code looks like this:

 client = Client.GetCoreService();

 if (string.IsNullOrEmpty(username)) username = HttpContext.Current.User.Identity.Name;
      client.Impersonate(username);

and this is the GetCoreService method:

public static SessionAwareCoreServiceClient GetCoreService()
{
       AppSettingsReader reader = new AppSettingsReader();

       string coreServiceUrl = (string)reader.GetValue("CoreServiceEndPoint", typeof(string));
       int dataSize = (int)reader.GetValue("DataSize", typeof(int));

       var quotas = new System.Xml.XmlDictionaryReaderQuotas
       {
           MaxStringContentLength = dataSize,
           MaxArrayLength = dataSize,
           MaxBytesPerRead = dataSize
       };

       var httpBinding = new WSHttpBinding
       {
           MaxReceivedMessageSize = 10485760,
           ReaderQuotas = quotas,
           Security = { Mode = SecurityMode.Message, Transport = { ClientCredentialType = HttpClientCredentialType.Windows } }
       };

       var endpoint = new EndpointAddress(coreServiceUrl);
       var result = new SessionAwareCoreServiceClient(httpBinding, endpoint);

       return result;
  }

extract from appsettings (replaced actual hostname with "hostname"):

<add key="CoreServiceEndPoint" value="http://hostname/WebServices/CoreService.svc/wsHttp_2010" />
<add key="DataSize" value="41943040" />
like image 566
Andreas Nellmon Avatar asked Dec 12 '12 09:12

Andreas Nellmon


2 Answers

Take a look at this sample from an open source project for notification which does what you need

http://code.google.com/p/tridion-notification-framework/source/browse/NotificationService/NotificationService/CoreService/Client.cs

Here is the working line which impersonates

public static SessionAwareCoreServiceClient GetCoreService()
{
    var result = GetNewClient<SessionAwareCoreServiceClient>();


    result.Impersonate(ConfigurationManager.AppSettings.Get("adminUser"));
    return result;
}

Also take a look at the way the client is created in the sample in the same CS file, and the App Settings. I think you are using an old endpoint address, it should be http://hostname/webservices/CoreService2011.svc/wsHttp rather than http://hostname/WebServices/CoreService.svc/wsHttp_2010

like image 149
GourmetCMS Avatar answered Jan 06 '23 22:01

GourmetCMS


You are connecting to an old Core Service wsHttp endpoint.

If you are using the 2011 SP1 client, you need to connect to the following endpoint instead:

http://hostname/webservices/CoreService2011.svc/wsHttp

like image 42
Peter Kjaer Avatar answered Jan 06 '23 22:01

Peter Kjaer