我爱LINQPad!我正在尝试使用 LINQPad 中的 WCF 连接器连接到 Tridion Core Services,以帮助我快速开发和学习 Core。
目前,LINQPad 正在报告 URI 的 404(未找到)错误,但这个相同的 URI 在我的浏览器中有效。
还有人成功连接吗?
LINQPad 的连接窗口
LINQPad 现在是我通过其核心服务 API 与 Tridion 交互的首选工具。
如果您只是下载一个普通的 LINQPad,它可以连接到 WCF 数据服务(通常称为 OData 源)、SQL Server 数据库和 Azure 数据服务市场。由于 Tridion 的核心服务不是这些类型,因此您无法创建到它的持久连接。
但是您仍然可以按照以下步骤使用 LINQPad 作为 Visual Studio 的轻量级替代品:
LINQPad 可以处理多种语言。它默认为“C# 表达式”,这意味着您只需在代码面板中指定一个“语句”。这在使用驱动程序可用的 SQL 数据库时非常有效,但不足以与 Tridion 的核心服务交互。因此,首先您需要在查询顶部的工具栏中将其从“C# 表达式”语言切换为“C# 程序”语言。
切换语言后,我通常从以下样板开始
void Main()
{
// System.Runtime.Serialization.dll
// System.ServiceModel.dll
// System.Net.dll
// Namespaces:
// System.Net
// System.ServiceModel
// Tridion.ContentManager.CoreService.Client
var binding = new NetTcpBinding { MaxReceivedMessageSize = 2147483647, ReaderQuotas = new XmlDictionaryReaderQuotas { MaxStringContentLength = 2147483647, MaxArrayLength = 2147483647 } };
var endpoint = new EndpointAddress("net.tcp://<hostname>:2660/CoreService/2011/netTcp");
var DEFAULT_READ_OPTIONS = new ReadOptions();
CoreServiceClient client = new CoreServiceClient(binding, endpoint);
client.ChannelFactory.Credentials.Windows.ClientCredential = new NetworkCredential("<username>", "<password>");
try {
// TODO: fill in the blanks
} finally {
if (client.State == CommunicationState.Faulted) client.Abort(); else client.Close();
}
}
粘贴此代码后,打开 Query Properties 窗口 (F4) 并将System.Runtime.Serialization.dll
,System.ServiceModel.dll
和添加System.Net.dll
到 Additional References 选项卡。确保您的机器上有 Tridion.ContentManager.CoreService.Client.dll 的副本,并添加对它的引用。(您可以在服务器上的 Tridion/bin/client 中找到它)
将System.Net
,System.ServiceModel
和添加Tridion.ContentManager.CoreService.Client
到 Additional Namespace Imports 选项卡。
更改代码中的<hostname>
,<username>
和<password>
值并测试连接是否成功。
在此之后,填空并开始享受核心服务 API 的乐趣。
我建议始终保持核心服务 API 文档(CHM 格式)打开。有了那个打开,我发现即使没有自动完成,我也能走得很远。如果您保存刚刚创建的查询,您可以使用 ctrl-shift-C 轻松克隆它,并使用已填写的语言、DLL 引用和命名空间进行新查询。
现在记录了从 LINQPad 连接到 Tridion 的更简单方法:https ://sdltridionworld.com/articles/sdltridion2011/using_linqpad_with_tridion.aspx
通读:http : //markistaylor.com/2010/09/09/linqpad-beyond-linq/ 似乎您可以通过添加对 System.ServiceModel.dll 和 [Tridion_Home]\bin 的引用来做到这一点\client\Tridion.ContentManager.CoreService.Client.dll(在查询 -> 查询属性下)到 LINQPad。
您可以检查内容管理器的 IIS 日志 - 您是否看到 LINQPaD 连接尝试中的 404?页面真的存在吗?