本文整理汇总了C#中ServiceContext.Execute方法的典型用法代码示例。如果您正苦于以下问题:C# ServiceContext.Execute方法的具体用法?C# ServiceContext.Execute怎么用?C# ServiceContext.Execute使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ServiceContext
的用法示例。
在下文中一共展示了ServiceContext.Execute方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Run
/// <summary>
/// This method first creates sample articles and publishes them, then searches
/// for the articles by body, keyword and title. Finally, it retrieves the
/// articles by top incident subject and top incident product.
/// </summary>
/// <param name="serverConfig">Contains server connection information.</param>
/// <param name="promptforDelete">When True, the user will be prompted to delete all
/// created entities.</param>
public void Run(ServerConnection.Configuration serverConfig, bool promptforDelete)
{
try
{
//<snippetSearchAndRetrieveArticles1>
// Connect to the Organization service.
// The using statement assures that the service proxy will be properly disposed.
using (_serviceProxy = new OrganizationServiceProxy(serverConfig.OrganizationUri, serverConfig.HomeRealmUri,serverConfig.Credentials, serverConfig.DeviceCredentials))
// Using the ServiceContext class makes the queries easier
using (_context = new ServiceContext(_serviceProxy))
{
// This statement is required to enable early-bound type support.
_serviceProxy.EnableProxyTypes();
CreateRequiredRecords();
#region Search Knowledge base by Body
//<snippetSearchByBodyKbArticle>
// Create the request
SearchByBodyKbArticleRequest searchByBodyRequest =
new SearchByBodyKbArticleRequest()
{
SubjectId = _subjectId,
UseInflection = true, // allows for a different tense or
// inflection to be substituted for the search text
SearchText = "contained", // will also match on 'contains'
QueryExpression = new QueryExpression()
{
ColumnSet = new ColumnSet("articlexml"),
EntityName = KbArticle.EntityLogicalName
}
};
// Execute the request
Console.WriteLine(" Searching for published article with 'contained' in the body");
SearchByBodyKbArticleResponse seachByBodyResponse =
(SearchByBodyKbArticleResponse)_context.Execute(searchByBodyRequest);
// Check success
var retrievedArticleBodies = seachByBodyResponse.EntityCollection.Entities
.Select((entity) => ((KbArticle)entity).ArticleXml);
if (retrievedArticleBodies.Count() == 0)
throw new Exception("No articles found");
Console.WriteLine(" Results of search (article bodies found):");
foreach (var body in retrievedArticleBodies)
Console.WriteLine(body);
//</snippetSearchByBodyKbArticle>
#endregion
#region Search knowledge base by Keyword
//<snippetSearchByKeywordsKbArticle>
// Create the request
SearchByKeywordsKbArticleRequest searchByKeywordRequest =
new SearchByKeywordsKbArticleRequest()
{
SubjectId = _subjectId,
UseInflection = true,
SearchText = "Search",
QueryExpression = new QueryExpression()
{
ColumnSet = new ColumnSet("keywords"),
EntityName = KbArticle.EntityLogicalName
}
};
// Execute the request
Console.WriteLine();
Console.WriteLine(" Searching for published article with 'search' as a keyword");
var searchByKeywordResponse =
(SearchByKeywordsKbArticleResponse)_context.Execute(searchByKeywordRequest);
// Check success
var retrievedArticleKeywords = searchByKeywordResponse.EntityCollection.Entities
.Select((entity) => (KbArticle)entity);
if (retrievedArticleKeywords.Count() == 0)
throw new Exception("No articles found");
Console.WriteLine(" Results of search (keywords found):");
foreach (var article in retrievedArticleKeywords)
Console.WriteLine(article.KeyWords);
//</snippetSearchByKeywordsKbArticle>
#endregion
//.........这里部分代码省略.........