我正在使用 Tridion 2011 SP1 并使用此处的代码连接到 CoreService:
http://code.google.com/p/tridion-practice/wiki/GetCoreServiceClientWithoutConfigFile
但是当我尝试做任何简单的操作时,例如:
XElement resultXml = _coreService.GetListXml(publicationId, filterData);
我收到以下错误消息。
"{"由于 EndpointDispatcher 的 ContractFilter 不匹配,接收方无法处理带有 Action 'http://www.sdltridion.com/ContentManager/CoreService/2011/ICoreService/Create' 的消息。这可能是因为合约不匹配(发送方和接收方之间的操作不匹配)或发送方和接收方之间的绑定/安全不匹配。检查发送方和接收方是否具有相同的合同和相同的绑定(包括安全要求,例如消息、传输、无)。"}"
有任何想法吗?
完整代码在这里:
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();
}
更新:
感谢 Nuno 和 Frank 的回复,我现在通过添加服务引用使其工作,只是有点好奇为什么我的代码不起作用,因为它创建了以下绑定,据我所知(我很可能错过了一些东西)上面的代码
同样适用于 Nuno 的方法 - 谢谢 Nuno。
<basicHttpBinding>
<binding name="basicHttp_2010">
<security mode="TransportCredentialOnly">
<transport clientCredentialType="Windows" />
</security>
</binding>
</basicHttpBinding>