[英]Tridion 2011 CoreService Connection
我正在使用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>
这不是您的问题的答案,但现在我如何处理核心服务客户端:
然后在代码中执行此操作:
SessionAwareCoreServiceClient client = new SessionAwareCoreServiceClient("netTcp_2011");
完成。
PS - 关于Frank的建议,将其添加到Tridion Practice wiki: http : //code.google.com/p/tridion-practice/wiki/GetCoreServiceClientWithConfigFile
看起来您创建的绑定与服务器期望的内容不一致。 查看TCM服务器上的.config并确保客户端创建相同类型的绑定。
您正在连接到错误的端点。 您无法使用“2011”客户端连接到“2010”版本的核心服务。
您应该连接到2011端点(... / webservices / CoreService2011.svc / basicHttp)
当然,您也可以更改对2010版客户端的引用,但除非您遇到问题,否则我不会这样做。
我通过在我的app配置中更改/ CoreService / 2012 /到/ CoreService / 2013 /来修复了同样的错误:
<endpoint name="netTcp_2012" address="net.tcp://localhost:2660/CoreService/2013/netTcp" binding="netTcpBinding" bindingConfiguration="netTcp" contract="Tridion.ContentManager.CoreService.Client.ISessionAwareCoreService" />
我怀疑我最初在Tridion 2011中创建了我的核心服务应用程序,然后我尝试使用Tridion 2013运行它。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.