Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Tridion 2011 CoreService Connection

I am using Tridion 2011 SP1 and am connecting to the CoreService using the code from here:

http://code.google.com/p/tridion-practice/wiki/GetCoreServiceClientWithoutConfigFile

But when i try to do any simple operation, such as this:

XElement resultXml = _coreService.GetListXml(publicationId, filterData);

I get the below error message.

"{"The message with Action 'http://www.sdltridion.com/ContentManager/CoreService/2011/ICoreService/Create' cannot be processed at the receiver, due to a ContractFilter mismatch at the EndpointDispatcher. This may be because of either a contract mismatch (mismatched Actions between sender and receiver) or a binding/security mismatch between the sender and the receiver. Check that sender and receiver have the same contract and the same binding (including security requirements, e.g. Message, Transport, None)."}"

Any Ideas?

Full code here:

            RepositoryItemsFilterData filterData = new RepositoryItemsFilterData();
            filterData.ItemTypes = new[]
                           {
                             ItemType.Component,
                             ItemType.Schema
                           };
            filterData.Recursive = true;

             ICoreService _coreService = GetNewClient(); 
             XElement resultXml = _coreService.GetListXml(publicationId, filterData);


       private ICoreService GetNewClient()
        {
            var binding = new BasicHttpBinding()
            {
                MaxBufferSize = 4194304, // 4MB
                MaxBufferPoolSize = 4194304,
                MaxReceivedMessageSize = 4194304,
                ReaderQuotas = new System.Xml.XmlDictionaryReaderQuotas()
                {
                    MaxStringContentLength = 4194304, // 4MB
                    MaxArrayLength = 4194304,
                },
                Security = new BasicHttpSecurity()
                {
                    Mode = BasicHttpSecurityMode.TransportCredentialOnly,
                    Transport = new HttpTransportSecurity()
                    {
                        ClientCredentialType = HttpClientCredentialType.Windows,
                    }
                }
            };
            _hostname = string.Format("{0}{1}{2}", _hostname.StartsWith("http") ? "" : "http://", _hostname, _hostname.EndsWith("/") ? "" : "/");
            var endpoint = new EndpointAddress(_hostname + "webservices/CoreService.svc/basicHttp_2010");
            ChannelFactory<ICoreService> factory = new ChannelFactory<ICoreService>(binding, endpoint);
            factory.Credentials.Windows.ClientCredential = new System.Net.NetworkCredential(_username, _password);
            return factory.CreateChannel();
        }



UPDATE: Thanks for the response's Nuno & Frank, i have it working now by adding a service reference, just a bit curious why my code didn't work though because it creates the below bindings, which are, as far as i can see (and i may well have missed something) the same the code above
Nuno's approach also works - thanks Nuno.

<basicHttpBinding> <binding name="basicHttp_2010"> <security mode="TransportCredentialOnly"> <transport clientCredentialType="Windows" /> </security> </binding> </basicHttpBinding>

like image 581
PeteN Avatar asked Sep 18 '12 19:09

PeteN


2 Answers

This is not the answer to your question, but here's how I deal with Core Service clients nowadays:

  1. Add a reference to [Tridion]\bin\client\Tridion.ContentManager.CoreService.Client.dll
  2. Copy the contents of [Tridion]\bin\client\Tridion.ContentManager.CoreService.Client.dll.Config into my own app.config

Then in code just do this:

SessionAwareCoreServiceClient client = new SessionAwareCoreServiceClient("netTcp_2011");

Done.

PS - On Frank's suggestion, added this to the Tridion Practice wiki: http://code.google.com/p/tridion-practice/wiki/GetCoreServiceClientWithConfigFile

like image 118
Nuno Linhares Avatar answered Oct 18 '22 20:10

Nuno Linhares


It looks like the bindings you create are not in-line with what the server expects. Have a look at the .config on your TCM server and make sure that the client-side creates the same type of binding.

like image 39
Frank van Puffelen Avatar answered Oct 18 '22 21:10

Frank van Puffelen