5

I am developing a ASP.NET (C#) web application that will run on a Content Manager server which will use Tridion 2013 core service.

How should I configure my web application to use core service? Should I just reference the core service assemblies in my project or I also have to configure an end point?

I have seen many examples but mostly using MVC, which I am not doing.

I am building a simple web application which will use core service to add/modify/delete Tridion users, get publication details report, etc.

Any sample project would be really appreciated

8

If you're starting out with the Core Service then I'd highly recommend that you check out the Core Service Recipes section of the Tridion Practice project on GitHub.

This has examples of getting a Core Service client with and without a config file.

I would also recommend reading the Interacting with the Core Service from client-side .NET section of the online documentation thoroughly.

4

Below are the steps you may follow to get started .

STEP 1: Identifying the Core Service Endpoints:

The Tridion Core Service End Points are present in the file: Tridion.ContentManager.CoreService.Client.dll.config at Path: %TRIDION_HOME%\bin\client\ on the Tridion Server.

They will look something as below:

<client>

      <endpoint name="basicHttp_2013" 
               address="http://localhost/webservices/CoreService2013.svc/basicHttp" 
               binding="basicHttpBinding" bindingConfiguration="basicHttp"
               contract="Tridion.ContentManager.CoreService.Client.ICoreService"/>
      <!-- Some More Endpoints will be there here -->
</client>


STEP 2: Adding reference to Core Service

  • Add reference to the Tridion DLL: Tridion.ContentManager.CoreService.Client.dll
  • Add the Service Endpoints in your Web.Config (Web Applications ) or in your App.config if using any Console Project.

STEP 3: Initializing the Core Service

Create a Class and initialize the Core Service in the Constructor of the class. Supply the required UserName / Password and use any of the End Points as in Step 1

public class TridionCoreServiceHelper
    {
        // This EndPoint Name is in the Config as mentioned above
        private readonly string endpointName = "basicHttp_2013";
        public TridionCoreServiceHelper()
        {
          client = new CoreServiceClient(endpointName);
          client.ClientCredentials.UserName.UserName = // User_Name
          client.ClientCredentials.UserName.Password = //Password
        }    

       private CoreServiceClient client;
    }


STEP 4: Querying using Tridion Core Service

Once the Service is initialized, Perform the Queries like the Publications List, Publication Targets ...

    public XElement GetPublicationList()
        {
            PublicationsFilterData filter = new PublicationsFilterData();
            return client.GetSystemWideListXml(filter);
        }

    public XElement GetPublicationTargetList()
        {
            PublicationTargetsFilterData filter = new PublicationTargetsFilterData();
            return client.GetSystemWideListXml(filter);
        }

Get the Users:

public XElement GetUserGrouptList()
        {
            UsersFilterData filter = new UsersFilterData();
            return client.GetSystemWideListXml(filter);
        }

SAMPLE PROJECT: Check this one of the best sample Project by Yabolka on Git Hub

URL : https://github.com/yabolka/TridionCoreServiceAPI

  • 1
    Note that if you host your web application in the CM website, you don't have to worry about the Core Service endpoint configuration: your web app will inherit the configuration defined in the CM website root's web.config. – Rick Pannekoek Sep 25 '15 at 9:55
  • Great Point Rick ! – R.C Sep 25 '15 at 10:08
3

You can use the code below to create a core service client in your web application:

/// <summary>
/// Core service client configuration
/// </summary>
/// <returns>return the client detail</returns>
public static CoreServiceClient GetCoreServiceSettings()
{
   var binding = new NetTcpBinding
   {
       MaxReceivedMessageSize = 2147483647,
       ReaderQuotas = new XmlDictionaryReaderQuotas
       {
           MaxStringContentLength = 2147483647,
           MaxArrayLength = 2147483647
       }
    };

    var endpoint = new EndpointAddress("net.tcp://localhost:2660/CoreService/2013/netTcp");

    var client = new CoreServiceClient(binding, endpoint);
    client.ChannelFactory.Credentials.Windows.ClientCredential = new NetworkCredential(
                                                                     "YourAdminUserID",
                                                                     "Password");
    return client;
}
0

you need to define <bindings><basicHttpBinding> inside <System.serviceModel> of your config file. Then add your:- <client><endpoint name="basicHttp_2013" **or** <endpoint name="netTcp_2013"

  <client>
      <endpoint name="basicHttp_2013" address="http://1.1.1.1/webservices/CoreService2013.svc/basicHttp" binding="basicHttpBinding" bindingConfiguration="basicHttp" contract="Tridion.ContentManager.CoreService.Client.ICoreService" />
      <endpoint name="streamDownload_basicHttp_2013" address="http://1.1.1.1/webservices/CoreService2013.svc/streamDownload_basicHttp" binding="basicHttpBinding" bindingConfiguration="streamDownload_basicHttp" contract="Tridion.ContentManager.CoreService.Client.IStreamDownload" />
      <endpoint name="streamUpload_basicHttp_2013" address="http://1.1.1.1/webservices/CoreService2013.svc/streamUpload_basicHttp" binding="basicHttpBinding" bindingConfiguration="streamUpload_basicHttp" contract="Tridion.ContentManager.CoreService.Client.IStreamUpload" />

      <endpoint name="netTcp_2013" address="net.tcp://localhost:protnumber/CoreService/2013/netTcp" binding="netTcpBinding" bindingConfiguration="netTcp" contract="Tridion.ContentManager.CoreService.Client.ISessionAwareCoreService" />
    </client>

then -----------------------Create client---------------------------

CoreServiceClient client = new CoreServiceClient("basicHttp_2013"); // If outside the server 
    or
SessionAwareCoreServiceClient client = new SessionAwareCoreServiceClient("netTcp_2013");  // From localhost    
client.Impersonate("userName"); 

Sample project is stated in above answers

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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