---
title: "ウォークスルー:接触と交流の側面を設定する"
slug: "walkthrough--setting-contact-and-interaction-facets"
abstract: "Sitecore xConnectで接触およびインタラクションの側面を設定する方法。"
---
# ウォークスルー:接触と交流の側面を設定する

このウォークスルーは「 [xConnectコレクションのモデルを拡張](https://doc.sitecore.com/xp/ja/developers/93/sitecore-experience-platform/extending-the-xconnect-collection-model-walkthrough-series.html "Extending the xConnect collection model walkthrough series")する」シリーズの第2部です。このウォークスルーを完了するには、まずウォークスルーパート[1](https://doc.sitecore.com/xp/ja/developers/93/sitecore-experience-platform/walkthrough--creating-a-contact-and-an-interaction.html "Walkthrough: Creating a contact and an interaction")をクリアする必要があります。

Sitecoreのデフォルトファセットは [コレクションモデル参照](https://doc.sitecore.com/xp/ja/developers/93/sitecore-experience-platform/collection-model-reference.html "Collection model reference") ドキュメントに記載されています。

もしファセットにプロパティが必要な場合は、ファセットコンストラクタで渡す必要があります。プロパティがコンストラクタになければ必須ではありません。

このウォークスルーでは、以下の方法を説明します:

-   コンタクトにフェイスを設定しましょう
-   相互作用の側面を設定する

> !注Sitecore 9.1.0のSitecore.Xdb.Common.Web名前空間では:
> 
> -   Certificate\*\*WebRequest\*\*HandlerModifierOptionsCertificate\*\*HttpClient\*\*HandlerModifierOptionsになった。
>     
> -   Certificate\*\*WebRequest\*\*HandlerModifierCertificate\*\*HttpClient\*\*HandlerModifierになった。
>     

## コンタクトにフェイスを設定しましょう

コンタクトのファセットを設定するには:

1.  Visual Studio、Solution ExplorerではProgram.csファイルをダブルクリックし、内容を以下のコードに置き換えてください。
    
    using Sitecore.XConnect;
    using Sitecore.XConnect.Client;
    using Sitecore.XConnect.Client.WebApi;
    using Sitecore.XConnect.Collection.Model;
    using Sitecore.XConnect.Schema;
    using Sitecore.Xdb.Common.Web;
    using System;
    using System.Collections.Generic;
    using System.Threading.Tasks;
    
    namespace Sitecore.Documentation
    {
     public class Program
     {
     // From <xConnect instance>\\App\_Config\\AppSettings.config
     const string CERTIFICATE\_OPTIONS =
     "StoreName=My;StoreLocation=LocalMachine;FindType=FindByThumbprint;FindValue=???";
    
     // From your installation
     const string XCONNECT\_URL = "https://???XConnect.local";
    
     private static void Main(string args)
     {
     MainAsync(args).ConfigureAwait(false).GetAwaiter().GetResult();
     System.Console.ForegroundColor = ConsoleColor.DarkGreen;
     System.Console.WriteLine("");
     Console.WriteLine("END OF PROGRAM.");
     Console.ReadKey();
     }
    
     private static async Task MainAsync(string args)
     {
     CertificateHttpClientHandlerModifierOptions options = CertificateHttpClientHandlerModifierOptions.Parse(CERTIFICATE\_OPTIONS);
    
     var certificateModifier = new CertificateHttpClientHandlerModifier(options);
    
     List<IHttpClientModifier> clientModifiers = new List<IHttpClientModifier>();
     var timeoutClientModifier = new TimeoutHttpClientModifier(new TimeSpan(0, 0, 20));
     clientModifiers.Add(timeoutClientModifier);
    
     var collectionClient = new CollectionWebApiClient(
     new Uri(XCONNECT\_URL + "/odata"),
     clientModifiers,
     new { certificateModifier }
     );
    
     var searchClient = new SearchWebApiClient(
     new Uri(XCONNECT\_URL + "/odata"),
     clientModifiers,
     new { certificateModifier }
     );
    
     var configurationClient = new ConfigurationWebApiClient(
     new Uri(XCONNECT\_URL + "/configuration"),
     clientModifiers,
     new { certificateModifier }
     );
    
     var cfg = new XConnectClientConfiguration(
     new XdbRuntimeModel(CollectionModel.Model),
     collectionClient,
     searchClient,
     configurationClient
     );
    
     try
     {
     cfg.Initialize();
    
     // Print xConnect if configuration is valid
     var arr = new
     {
     @" \_\_\_\_\_\_ \_\_ ",
     @" / \\ | \\ ",
     @" \_\_ \_\_ | $$$$$$\\ \_\_\_\_\_\_ \_\_\_\_\_\_\_ \_\_\_\_\_\_\_ \_\_\_\_\_\_ \_\_\_\_\_\_\_ \_| $$\_ ",
     @"| \\ / \\| $$ \\$$ / \\ | \\ | \\ / \\ / \\| $$ \\ ",
     @"\\$$\\/ $$| $$ | $$$$$$\\| $$$$$$$\\| $$$$$$$\\| $$$$$$\\| $$$$$$$ \\$$$$$$ ",
     @" >$$ $$ | $$ \_\_ | $$ | $$| $$ | $$| $$ | $$| $$ $$| $$ | $$ \_\_ ",
     @" / $$$$\\ | $$\_\_/ \\| $$\_\_/ $$| $$ | $$| $$ | $$| $$$$$$$$| $$\_\_\_\_\_ | $$| \\",
     @"| $$ \\$$\\ \\$$ $$ \\$$ $$| $$ | $$| $$ | $$ \\$$ \\ \\$$ \\ \\$$ $$",
     @" \\$$ \\$$ \\$$$$$$ \\$$$$$$ \\$$ \\$$ \\$$ \\$$ \\$$$$$$$ \\$$$$$$$ \\$$$$ "
     };
     Console.WindowWidth = 160;
     foreach (string line in arr)
     Console.WriteLine(line);
    
     }
     catch (XdbModelConflictException ce)
     {
     Console.WriteLine("ERROR:" + ce.Message);
     return;
     }
    
     // Initialize a client using the validated configuration
     using (var client = new XConnectClient(cfg))
     {
     try
     {
     var offlineGoal = Guid.Parse("ad8ab7fe-ab48-4ea9-a976-ae7a268ae2f0"); // "Watched demo" goal
     var channelId = Guid.Parse("110cbf07-6b1a-4743-a398-6749acfcd7aa"); // "Other event" channel
    
     // Identifier for a 'known' contact
     var identifier = new ContactIdentifier
     {
     new ContactIdentifier(
     "twitter",
     "myrtlesitecore" + Guid.NewGuid().ToString("N"),
     ContactIdentifierType.Known
     )
     };
    
     // Print out the identifier that is going to be used
     Console.WriteLine("Contact Identifier: " + identifier0.Identifier);
    
     // Create a new contact with the identifier
     Contact knownContact = new Contact(identifier);
    
     PersonalInformation personalInfoFacet = new PersonalInformation();
    
     personalInfoFacet.FirstName = "Myrtle";
     personalInfoFacet.LastName = "McSitecore";
     personalInfoFacet.JobTitle = "Programmer Writer";
    
     client.SetFacet<PersonalInformation>(
     knownContact,
     PersonalInformation.DefaultFacetKey,
     personalInfoFacet
     );
    
     client.AddContact(knownContact);
    
     // Create a new interaction for that contact
     Interaction interaction = new Interaction(knownContact, InteractionInitiator.Brand, channelId, "");
    
     // Add events - all interactions must have at least one event
     var xConnectEvent = new Goal(offlineGoal, DateTime.UtcNow);
     interaction.Events.Add(xConnectEvent);
    
     // Add the contact and interaction
     client.AddInteraction(interaction);
    
     // Submit contact and interaction - a total of two operations
     await client.SubmitAsync();
    
     // Get the last batch that was executed
     var operations = client.LastBatch;
    
     // Loop through operations and check status
     foreach (var operation in operations)
     {
     Console.WriteLine(
     operation.OperationType
     + operation.Target.GetType().ToString()
     + " Operation: "
     + operation.Status
     );
     }
    
     Console.ReadLine();
     }
     catch (XdbExecutionException ex)
     {
     // Deal with exception
     }
     }
     }
     }
    }
    
2.  CERTIFICATE\_THUMBPRINTとXCONNECT\_URL定数を編集してください。
    
3.  Program.csファイルを保存してください。
    
4.  **F5**を押してアプリを起動します。接続が確立されると、アプリはターミナルに次のように書き込みます:
    
    -   連絡先識別子。
    -   その側面はコンタクトに設定されていました。
    -   連絡先が追加されたということです。
    -   イベントとのインタラクションが追加されたのです。
    
    ![A terminal with the contact, facet, contract, and interactive event details in the app output.](https://doc.sitecore.com/api/markdown-image/xp/ja/developers/93/sitecore-experience-platform/images/xconn-tut2-code1.png)
    

## 相互作用の側面を設定する

相互作用の側面を設定するために:

1.  Visual Studio、Solution ExplorerではProgram.csファイルをダブルクリックし、内容を以下のコードに置き換えてください。
    
    using Sitecore.XConnect;
    using Sitecore.XConnect.Client;
    using Sitecore.XConnect.Client.WebApi;
    using Sitecore.XConnect.Collection.Model;
    using Sitecore.XConnect.Schema;
    using Sitecore.Xdb.Common.Web;
    using System;
    using System.Collections.Generic;
    using System.Threading.Tasks;
    
    namespace Sitecore.Documentation
    {
     public class Program
     {
     // From <xConnect instance>\\App\_Config\\AppSettings.config
     const string CERTIFICATE\_OPTIONS =
     "StoreName=My;StoreLocation=LocalMachine;FindType=FindByThumbprint;FindValue=???";
    
     // From your installation
     const string XCONNECT\_URL = "https://???XConnect.local";
    
     private static void Main(string args)
     {
     MainAsync(args).ConfigureAwait(false).GetAwaiter().GetResult();
     System.Console.ForegroundColor = ConsoleColor.DarkGreen;
     System.Console.WriteLine("");
     Console.WriteLine("END OF PROGRAM.");
     Console.ReadKey();
     }
    
     private static async Task MainAsync(string args)
     {
     CertificateHttpClientHandlerModifierOptions options = CertificateHttpClientHandlerModifierOptions.Parse(CERTIFICATE\_OPTIONS);
    
     var certificateModifier = new CertificateHttpClientHandlerModifier(options);
    
     List<IHttpClientModifier> clientModifiers = new List<IHttpClientModifier>();
     var timeoutClientModifier = new TimeoutHttpClientModifier(new TimeSpan(0, 0, 20));
     clientModifiers.Add(timeoutClientModifier);
    
     var collectionClient = new CollectionWebApiClient(
     new Uri(XCONNECT\_URL + "/odata"),
     clientModifiers,
     new { certificateModifier }
     );
    
     var searchClient = new SearchWebApiClient(
     new Uri(XCONNECT\_URL + "/odata"),
     clientModifiers,
     new { certificateModifier }
     );
    
     var configurationClient = new ConfigurationWebApiClient(
     new Uri(XCONNECT\_URL + "/configuration"),
     clientModifiers,
     new { certificateModifier }
     );
    
     var cfg = new XConnectClientConfiguration(
     new XdbRuntimeModel(CollectionModel.Model),
     collectionClient,
     searchClient,
     configurationClient
     );
    
     try
     {
     cfg.Initialize();
    
     // Print xConnect if configuration is valid
     var arr = new
     {
     @" \_\_\_\_\_\_ \_\_ ",
     @" / \\ | \\ ",
     @" \_\_ \_\_ | $$$$$$\\ \_\_\_\_\_\_ \_\_\_\_\_\_\_ \_\_\_\_\_\_\_ \_\_\_\_\_\_ \_\_\_\_\_\_\_ \_| $$\_ ",
     @"| \\ / \\| $$ \\$$ / \\ | \\ | \\ / \\ / \\| $$ \\ ",
     @"\\$$\\/ $$| $$ | $$$$$$\\| $$$$$$$\\| $$$$$$$\\| $$$$$$\\| $$$$$$$ \\$$$$$$ ",
     @" >$$ $$ | $$ \_\_ | $$ | $$| $$ | $$| $$ | $$| $$ $$| $$ | $$ \_\_ ",
     @" / $$$$\\ | $$\_\_/ \\| $$\_\_/ $$| $$ | $$| $$ | $$| $$$$$$$$| $$\_\_\_\_\_ | $$| \\",
     @"| $$ \\$$\\ \\$$ $$ \\$$ $$| $$ | $$| $$ | $$ \\$$ \\ \\$$ \\ \\$$ $$",
     @" \\$$ \\$$ \\$$$$$$ \\$$$$$$ \\$$ \\$$ \\$$ \\$$ \\$$$$$$$ \\$$$$$$$ \\$$$$ "
     };
     Console.WindowWidth = 160;
     foreach (string line in arr)
     Console.WriteLine(line);
    
     }
     catch (XdbModelConflictException ce)
     {
     Console.WriteLine("ERROR:" + ce.Message);
     return;
     }
    
     // Initialize a client using the validated configuration
     using (var client = new XConnectClient(cfg))
     {
     try
     {
     var offlineGoal = Guid.Parse("ad8ab7fe-ab48-4ea9-a976-ae7a268ae2f0"); // "Watched demo" goal
     var channelId = Guid.Parse("110cbf07-6b1a-4743-a398-6749acfcd7aa"); // "Other event" channel
    
     // Identifier for a 'known' contact
     var identifier = new ContactIdentifier
     {
     new ContactIdentifier(
     "twitter",
     "myrtlesitecore" + Guid.NewGuid().ToString("N"),
     ContactIdentifierType.Known
     )
     };
    
     // Print out the identifier that is going to be used
     Console.WriteLine("Contact Identifier: " + identifier0.Identifier);
    
     // Create a new contact with the identifier
     Contact knownContact = new Contact(identifier);
    
     PersonalInformation personalInfoFacet = new PersonalInformation();
    
     personalInfoFacet.FirstName = "Myrtle";
     personalInfoFacet.LastName = "McSitecore";
     personalInfoFacet.JobTitle = "Programmer Writer";
    
     client.SetFacet<PersonalInformation>(
     knownContact,
     PersonalInformation.DefaultFacetKey,
     personalInfoFacet
     );
    
     client.AddContact(knownContact);
    
     // Create a new interaction for that contact
     Interaction interaction = new Interaction(knownContact, InteractionInitiator.Brand, channelId, "");
    
     // Add events - all interactions must have at least one event
     var xConnectEvent = new Goal(offlineGoal, DateTime.UtcNow);
     interaction.Events.Add(xConnectEvent);
    
     IpInfo ipInfo = new IpInfo("127.0.0.1");
     ipInfo.BusinessName = "Home";
     client.SetFacet<IpInfo>(interaction, IpInfo.DefaultFacetKey, ipInfo);
    
     // Add the contact and interaction
     client.AddInteraction(interaction);
    
     // Submit contact and interaction - a total of two operations
     await client.SubmitAsync();
    
     // Get the last batch that was executed
     var operations = client.LastBatch;
    
     // Loop through operations and check status
     foreach (var operation in operations)
     {
     Console.WriteLine(
     operation.OperationType
     + operation.Target.GetType().ToString()
     + " Operation: "
     + operation.Status
     );
     }
    
     Console.ReadLine();
     }
     catch (XdbExecutionException ex)
     {
     // Deal with exception
     }
     }
     }
     }
    }
    
2.  CERTIFICATE\_THUMBPRINTとXCONNECT\_URL定数を編集してください。
    
3.  Program.csファイルを保存してください。
    
4.  **F5**を押してアプリを起動します。接続が確立されると、アプリはターミナルに次のように書き込みます:
    
    -   連絡先識別子。
        
        > !重要連絡先識別子をメモしておく。次のウォークスルーで必要だ。
        
    -   その側面はコンタクトに設定されていました。
        
    -   連絡先が追加されたということです。
        
    -   その側面は相互作用に設定されていた。
        
    -   イベントとのインタラクションが追加されたのです。
        
    
    ![A terminal with the facet set on the contract and interaction, and contact and interaction event details in the app output.](https://doc.sitecore.com/api/markdown-image/xp/ja/developers/93/sitecore-experience-platform/images/xconn-tut2-code2.png)
    

次のウォークスルーで [連絡の取る](https://doc.sitecore.com/xp/ja/developers/93/sitecore-experience-platform/walkthrough--getting-contacts.html "Walkthrough: Getting contacts")方法を学んでください。