3

I'm trying to setup a new project to use Tridion.ContentManager.CoreService.Client.dll. I have successfully used this library in the past, but this time, my project is a .NET Core application.

Anyone been able to run a .NET Core 2 application using Tridion.ContentManager.CoreService.Client?

I'm getting this run-time error when I try to constructor a CoreServiceClient

An error occurred while loading attribute 'OperationContractAttribute' on method 'PurgeApplicationData' in type 'ICoreService'. Please see InnerException for more details.

Inner Exception 1: TypeLoadException: Could not load type 'System.ServiceModel.TransactionFlowAttribute' from assembly 'System.ServiceModel, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.

To get this far, I had to overcome a build-time error saying System.ServiceModel was not defined. That was overcome by adding NuGet packages System.ServiceModel.Primatives and System.ServiceModel.Http

2 Answers 2

2

Indeed. The current CoreService not supported with .Net Core, because it used the standard .NET Framework System.ServiceModel Version=4.0.0.0 which is not supported with .NET Core

Even I did try to create a service reference without referencing Tridion.ContentManager.CoreService.Client.dll to create the proxy class to try to connect coreservice. but complains about the following messages, and noticed it's only created Async methods.

Importing web service metadata ...
Number of service endpoints found: 5
Scaffolding service reference code ...
Restoring NuGet packages for bootstrapper ...
Building bootstrapper project ...
Invoking bootstrapper ...
Warning:Warning: Transaction flow is not supported.
Warning:Warning: Unsupported binding element type: 'System.ServiceModel.Channels.SymmetricSecurityBindingElement'.
Warning:Warning: Endpoint 'wsHttp' at address 'http://localhost:7086/webservices/CoreService201701.svc/wsHttp' contains one or more bindings not compatible with .Net Core apps, skipping...
Generating files...
Updating project ...
Done.

AFAIK - The engineering working on new Rest based coreservice APIs on the next version or so. I hope it will allow us to do .Net Core.

1
  • 2
    Although it doesn't support all the bindings and the 'sync' versions of the methods, it does work. And async is the way to go anyway :) Commented Oct 4, 2019 at 10:12
4

Good question. Recently I created a .Net Core WebApi project and it is working fine. Here is what I did:

Finally, here is an example of me calling the Core Service. Note, all methods in the Proxy are using Async. If you need to call a method without Async, then put .Result at the end of the call to the Core Service. But, I suggest to try to implement Task and Await as much as possible. I had to do this while requesting a PageData object:

 PageData page =  (PageData)client.ReadAsync(pageUri, new ReadOptions()).Result;

And here is the code to call the Core Service, and below it, 2 methods in the reference.cs file (in the Connected Services section of the Project)

    [HttpGet]
    [Route("getapiversion")]
    public async Task<ActionResult<string>> GetApiVersion()
    {
        CoreServiceClient client = new CoreServiceClient(CoreServiceClient.EndpointConfiguration.basicHttp, CoreServiceClient.TridionEnvironment.qa);

        try
        {
            string userName = "tridionUser";
            string password = "tridionPw";
            string domain = "domain";

            NetworkCredential creds = new NetworkCredential(userName, password, domain);
            client.ClientCredentials.Windows.ClientCredential = creds;
            return await client.GetApiVersionAsync();
        } 
        catch(Exception)
        {
            return this.StatusCode(StatusCodes.Status500InternalServerError, "Issues connecting to Tridion");
        }
    }


// In Reference.cs
private static System.ServiceModel.EndpointAddress GetEndpointAddress(EndpointConfiguration endpointConfiguration, TridionEnvironment environment)
{
    if ((endpointConfiguration == EndpointConfiguration.basicHttp))
    {
        if (environment == TridionEnvironment.qa)
        {
            return new System.ServiceModel.EndpointAddress("http://TridionCMS/webservices/CoreService2013.svc/basicHttp");
        }
        else if (environment == TridionEnvironment.dev)
        {
            return new System.ServiceModel.EndpointAddress("http://TridionCMS/webservices/CoreService2013.svc/basicHttp");
        }
        else if (environment == TridionEnvironment.prod)
        {
            return new System.ServiceModel.EndpointAddress("https://TridionCMS/webservices/CoreService2013.svc/basicHttp");
        }
        else
        {
            // default is QA
            return new System.ServiceModel.EndpointAddress("http://TridionCMS/webservices/CoreService2013.svc/basicHttp");
        }
    }
    throw new System.InvalidOperationException(string.Format("Could not find endpoint with name \'{0}\'.", endpointConfiguration));
}

public enum EndpointConfiguration
{

    basicHttp,
}

public enum TridionEnvironment
{
    dev,
    qa,
    prod
}
2
  • I haven't had the opportunity to try these ideas. I marked the other answer as the answer, but I hope to see a supported / strong solution come out. Thank you for sharing this effort.
    – MADCookie
    Commented Oct 15, 2019 at 18:15
  • 1
    At the Tridion Developer Summit (on 5-6 November in Amsterdam) SDL will be discussing future product direction and I will give a talk on the above solution.
    – robrtc
    Commented Oct 16, 2019 at 20:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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