csharp 使用SDL Tridion Core Service发布页面。此示例显示如何在没有配置文件和使用B的情况下使用Core Service API
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了csharp 使用SDL Tridion Core Service发布页面。此示例显示如何在没有配置文件和使用B的情况下使用Core Service API相关的知识,希望对你有一定的参考价值。
using System;
using System.ServiceModel;
using System.Xml;
using Tridion.ContentManager.CoreService.Client;
namespace TridionCoreserviceSession
{
/* SDL Tridion Core Service sesion.
* Based on http://yatb.mitza.net/2012/03/core-service-client-sample-code.html
*/
public class CoreServiceSession : IDisposable
{
private readonly CoreServiceClient _client;
private const string ServiceUrl = "http://{0}/webservices/CoreService2011.svc/basicHttp" ;
private const int MaxMessageSize = 10485760;
public CoreServiceSession(string hostname)
{
_client = CreateBasicHttpClient(hostname);
}
public CoreServiceSession(string hostname, string username, string password)
{
_client = CreateBasicHttpClient(hostname);
_client.ChannelFactory.Credentials.Windows.ClientCredential =
new System.Net.NetworkCredential (username, password);
}
private CoreServiceClient CreateBasicHttpClient(string hostname)
{
var basicHttpBinding = new BasicHttpBinding
{
MaxReceivedMessageSize = MaxMessageSize,
ReaderQuotas = new XmlDictionaryReaderQuotas
{
MaxStringContentLength = MaxMessageSize,
MaxArrayLength = MaxMessageSize
},
Security = new BasicHttpSecurity
{
Mode = BasicHttpSecurityMode.TransportCredentialOnly,
Transport = new HttpTransportSecurity
{
ClientCredentialType = HttpClientCredentialType.Windows
}
}
};
var remoteAddress = new EndpointAddress( string.Format(ServiceUrl, hostname));
return new CoreServiceClient(basicHttpBinding, remoteAddress); ;
}
public void Dispose()
{
if (_client.State == CommunicationState .Faulted)
{
_client.Abort();
}
else
{
_client.Close();
}
}
#region Core Service calls
// Calls to the Core Service client library. Extend the Core service calls as needed.
public UserData GetCurrentUser()
{
return _client.GetCurrentUser();
}
public PublishTransactionData [] Publish(string[] itemUris, PublishInstructionData publishInstructionData,
string[] destinationTargetUris, PublishPriority publishPriority, ReadOptions readOptions)
{
return _client.Publish(itemUris, publishInstructionData, destinationTargetUris, publishPriority, readOptions);
}
public IdentifiableObjectData Read(string id, ReadOptions readOptions)
{
return _client.Read(id, readOptions);
}
#endregion Core Service calls
}
}
using System;
using System.ServiceModel;
using Tridion.ContentManager.CoreService.Client;
using TridionCoreserviceSession;
...
// Make a Core Service connection
CoreServiceSession session = new CoreServiceSession( "localhost", "[username]" , "[password]");
try
{
// Display the current user
Console.WriteLine( "Current user is: " + session.GetCurrentUser().Title);
// Get a page
PageData page = ( PageData) session.Read("tcm:69-6943-64" , new ReadOptions());
Console.WriteLine( "Page title: " + page.Title);
// Publish the page
string[] pageUris = { "tcm:69-6943-64"};
string[] destinationTargetUris = { "tcm:0-1-65537"};
var publishInstruction = new PublishInstructionData
{
RenderInstruction = new RenderInstructionData(),
ResolveInstruction = new ResolveInstructionData()
};
PublishTransactionData[] publishTransactions = session.Publish(pageUris, publishInstruction,
destinationTargetUris, PublishPriority .Normal,
new ReadOptions());
Console.WriteLine( "Published page; transaction id: " + publishTransactions[0].Id);
}
catch (FaultException <CoreServiceFault> e)
{
// handle the exception
Console.WriteLine( String.Format("Error; Core Service said: {0}; {1} ", e.Detail.ErrorCode,
string.Join(", " , e.Detail.Messages)));
}
以上是关于csharp 使用SDL Tridion Core Service发布页面。此示例显示如何在没有配置文件和使用B的情况下使用Core Service API的主要内容,如果未能解决你的问题,请参考以下文章
csharp 创建一个SDL Tridion用户trhough CoreService。假设将Tridion核心服务客户端DLL配置为app.config
csharp 创建一个SDL Tridion用户trhough CoreService。假设将Tridion核心服务客户端DLL配置为app.config
csharp 检查TCM URI是否为ECL项。 (SDL Tridion 2013中的ECL API)
csharp 检查TCM URI是否为ECL项。 (SDL Tridion 2013中的ECL API)
csharp 示例SDL Tridion .Net模板,用于将JSON文件创建为包项,然后将其作为二进制变体发布
powershell 使用PowerShell和核心服务淘汰SDL Tridion 2013 SP1发布目标。见http://tridion.stackexchange.com/questions/1