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>