LINQPad is by now my tool of choice for interacting with Tridion through its Core Service API.
If you just download a plain LINQPad, it can connect to WCF data services (typically known as OData sources), SQL Server databases and to the Azure Data Services market. Since Tridion's Core Service is none of those types, you can not create a persistent connection to it.
But you can still use LINQPad as a lightweight alternative to Visual Studio by following these steps:
- Switch LINQPad's Language to "C# Program"
- Paste in the code snippet below
- Add the necessary DLL references from the code snippet
- Add the necessary Namespace references from the code snippet
- Specify your own values for hostname, username and password
- Write your code
LINQPad can handle multiple languages. It defaults to "C# Expression", which means you can just specify a single "statement" in the code panel. That works great when working with e.g. SQL databases for which a driver is available, but is not good enough for interacting with Tridion's Core Service. So first you need to switch it from "C# Expression" language to "C# Program" language in the toolbar at the top of your query.
After switching Language, I typically start with the following boilerplate
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();
}
}
After pasting this code, open the Query Properties window (F4) and add System.Runtime.Serialization.dll
, System.ServiceModel.dll
and System.Net.dll
to the Additional References tab. Make sure you have a copy of Tridion.ContentManager.CoreService.Client.dll on your machine and add a reference to that too. (You can find this in Tridion/bin/client on your server)
Add System.Net
, System.ServiceModel
and Tridion.ContentManager.CoreService.Client
to the Additional Namespace Imports tab.
Change the <hostname>
, <username>
and <password>
values in the code and test if the connection succeeds.
After this, fill in the blanks and start having fun with the Core Service API.
I recommend keeping the Core Service API documentation (in CHM format) open at all times. With that open I found that I could get pretty far even without auto-complete. And if you save the query you just created, you can easily clone it with ctrl-shift-C and have a fresh query with the Language, DLL references and Namespaces already filled in.
Update
A easier way to connect to Tridion from LINQPad is now documented here: https://sdltridionworld.com/articles/sdltridion2011/using_linqpad_with_tridion.aspx