Exercise 2: Creating a basic provider

In this exercise you will expand the test provider by replacing static friend and activity data with data that comes from a sample social service. You’ll call this social service using WCF. The social service is an example of how the OSC provider could be used in the enterprise. The sample social service returns a list of sales people as ‘friends’ and returns a sales information (i.e. Joe just closed a $35,500 deal!) as ‘activities’.

Task 1 – Launching the Sample Social Service

In this task you will build and launch a sample social service.

  1. Open up another instance of Visual Studio 2010 (Run as Administrator).
  2. Open the SocialService solution found in your Student directory
  3. Open the file Program.cs
  4. In the SocialService class there is a class variable DBPath – verify that the path to this database is correct. The database should be located in the SocialService directory.
  5. Press F5 to start this service

    Figure 7

    Social Service started

Task 2 – Implementing Calls to the Service in TestProvider

In this task you will perform the necessary modifications to the TestProvider project so that you can call methods in the SocialService service.

  1. Add SocialServiceProxy.cs to the TestProvider Project
    1. Copy the file SocialServiceProxy.cs found in the SocialService folder (C:\Student\OSC\SocialService\) to the TestProvider solution folder (C:\Student\OSC\TestProvider).
    2. In Visual Studio, right-click on the TestProvider project and choose AddExisting Item
    3. Locate SocialServiceProxy.cs and click Add
    4. Right-click on References in the Solution Explorer and choose Add Reference
    5. Click on the .NET tab
    6. Select System.ServiceModel and click OK
  2. Add a new class to the TestProvider project named SampleData.cs
    1. Right-click on the TestProvider project and choose AddClass
    2. Name the class SampleData.cs and click Add
    3. Scope the class SampleData as public
  3. Add a reference to System.Runtime.Serialization. You will use this assembly to access the XmlDictionaryReaderQuotas class necessary for configuring the WCF binding appropriately.
  4. Import necessary namespaces:

    C#

    using System.ServiceModel; using System.Xml;

  5. Add a static method called GetClient to the SampleData class. This method is responsible for specifying the binding and endpoint address required to access the SocialService.

    C#

    private static SocialServiceClient GetClient() { //Specify the binding to use for the client. BasicHttpBinding binding = new BasicHttpBinding(); // Increase the max string content length (default is 8192) XmlDictionaryReaderQuotas readerQuotas = new XmlDictionaryReaderQuotas(); readerQuotas.MaxStringContentLength = 524288; binding.ReaderQuotas = readerQuotas; //Specify the address to use for the client. EndpointAddress address = new EndpointAddress( "https://localhost:8000/SocialService/Service/SocialService"); return new SocialServiceClient(binding, address); }

  6. Add a static method called GetFriends() to call the GetFriends method exposed by the SocialService:

    C#

    public static string GetFriends(int ID) { string result = ""; SocialServiceClient client = GetClient(); result = client.GetFriends(ID); client.Close(); return result; }

  7. Add a static method called GetActivities() to call the GetActivities method exposed by the SocialService:

    C#

    public static string GetActivities(DateTime startDate) { string result = ""; SocialServiceClient client = GetClient(); result = client.GetActivities(startDate); client.Close(); return result; }

Task 3 – Modifying TestProvider to Call New SampleData Class Rather than Return Static Text

In this task you will perform the necessary modifications to the TestProvider project so that it calls the appropriate methods in SampleData to return friend and activity information.

  1. Modify the TestPerson class
    1. Expand the region ISocialPerson Members
    2. Modify GetActivities as shown below (changes in bold – note some of the changes include commenting out lines of code)

      C#

      public string GetActivities(DateTime startTime)
      FakePre-46de06305d7f48258546516bdf69bf31-9515479a306f4d07b48f6e58f78a2493//string result = Properties.Resources.activityFeed;FakePre-3651f20acf08464c9b8f7a01ed7f7a13-1d46df817ccc4f969f6679aa1fc3e6b4FakePre-b48b94d5a576451bb6669c763150ebf0-4b88c421ed984aafa475fa76dadb49f7FakePre-728fdda9e4d14fc7a3e588dc9b9f831b-926163a0c60844a68c598f9d7fb1294aFakePre-6e8c0226d2a44c74b4fbb3d113dad673-c8f57e0751ae44f281cda3c13d4537bc

    3. Modify GetDetails as shown below (changes in bold – note some of the changes include commenting out lines of code)

      C#

      public string GetDetails()
      FakePre-722df0c13abf434d96b4beaca274a38a-62a2c366e4444dc199a4adc885295067FakePre-fffac9cd82384670b2e07d585043c22f-9ead6334f4dc4bda868b0c9a89ef0496FakePre-65a7d9ace4734b10ad30c590fc01662b-340116d74d6f49418646ba225e070a8d//if (this.userid.Equals("4667647")) //{ result = Properties.Resources.friend1; } //if (this.userid.Equals("5015012")) //{ result = Properties.Resources.friend2; }FakePre-afd71c934fa24552a0da4527d558e3b8-283a770e8eed4656bc00b7872d4c9befFakePre-b9f6a03a4cdf40b5a84333663b056158-1bef1d6eb24743ffb8e2805e69dc7912FakePre-dc029dcea20d47ddb07db39577cd6764-9132d8d69e254000892bc91ae5dca796FakePre-55574129b2e44baeb15f1867d9c94f08-e2ea02bef3cb4b65bcd93ddd53edf0b5FakePre-d290660cf78f4e63a4de6f76131bea70-c2a9fbb908c249e589abf3fa2df6588a

    4. Modify GetFriendsandColleagues (changes in bold)

      C#

      public string GetFriendsAndColleagues()
      FakePre-16585906cfb94cf4a0d721601d18d5ca-a84f8083baf941ef83107110e90a99f3//string result = Properties.Resources.friends;FakePre-96974ee6e3a94ad2a7be3104e58f2f73-1b0e9f51af15418fb5f3ffa54da99912FakePre-4ea76a4099ae4224b3737137810e13b1-3cc7c04c0f3d480aaaee238b138fa23bFakePre-4b7004f98ad04881ba3953dcdbccbb6b-11244b0e03124d96a490e0ccd759ea32

  2. Modify the TestProfile class
    1. Expand the regions ISocialProfile Members and ISocialPerson members
    2. Modify GetActivitiesOfFriendsAndColleagues as shown below (changes in bold)

      C#

      public string GetActivitiesOfFriendsAndColleagues(DateTime startTime)
      FakePre-3924b614dd1b46df883855f3e81aff5e-13eefa01f6534f77a3558d594873897bFakePre-880b5833d5894e3aa33133ea14d969f5-74257a3ea36b4387a43647462540249a//string result = Properties.Resources.activityFeed;FakePre-6bce3346ecc343f6b2dc15e9959d3441-aba277303fbe4cf7b10a8d0cd052f2d0FakePre-04bcfda975e347a4943781e0392c7df2-2a28d2e5c8c64c0095d1d4707e873749FakePre-d34e0c7705c34a74b8068cddb0016a95-ce7794e1dba345598a7a37050fe6ccf1FakePre-03216246e8a040e789680f4f6bfc4919-9fb766cbc076409e800baa5131b8db74

    3. Modify GetActivities as shown below (changes in bold)

      C#

      public new string GetActivities(DateTime startTime)
      FakePre-8f619174aef14be0a3cbfe7b0f87ef62-7c2b1ff6c4f040b0919352695fdbf865//string result = Properties.Resources.activityFeed;FakePre-7ed4ac42a9fd4231ba451c20baa64ed5-94a65fa258704c648b7250ba0bba4aa5FakePre-eac3292cd3344c138f0c9031cc766dee-3b183646fa644c6894973483eb64998fFakePre-59786e79fab24a48b0a270476b723ee0-8404e13dc0374264b37733dab0ea74a2FakePre-2fe05823027344189f32eda650dda7c7-c8f1c955172548fb8448277b46fb6506

    4. Modify GetDetails as shown below (changes in bold)

      C#

      public new string GetDetails()
      FakePre-eaa3fdf7d3cf4b73b3bde9c86e13d5b0-2e30254760d84423983ddf8dc5d619eaFakePre-5fc9834aa50445deaf88e62d0cd73537-9d828cfe0a5a420f82c8717abcc007feFakePre-045440347edb4d0498273ff99634d684-e562e0d3e5b344088eef3d0fd84d1419//if (this.userid.Equals("4667647")) //{ result = Properties.Resources.friend1; } //if (this.userid.Equals("5015012")) //{ result = Properties.Resources.friend2; }FakePre-39c5147022294cccaa07e35f7500bcb6-bc2b7b5f71314475b2382fdf78e5a4adFakePre-d46111f1a2594b4e84ac8bb670e14dda-817d997c04da48538bcbec471f445898FakePre-bfcfdf3c152b4f0ab98d9aa08528677e-37547ca618ad4dc5bf952325301edfe3FakePre-cf27ce36fa2d4b238d55ff0550cb0042-dcba18f6736345209653a451c3aeab34FakePre-7c111aa73d9d4d5f8ed615c180376896-83df757258e846e682bb6050be2f8c05

    5. Modify GetFriendsAndColleagues as shown below (changes in bold)

      C#

      public new string GetFriendsAndColleagues()
      FakePre-191e93607a6d4fb5a320909b1afe9007-17cf252f4a8d43c89801d62c45934899//string result = Properties.Resources.friends; string result = SampleData.GetFriends(-1);FakePre-f8e2aefae9934b269c6b07714c149921-3872a7bc10e544b69a8aafd75a9bb19eFakePre-94441ca0f21643cc8689a2f5b8d9c7d9-54167bd207e84d3d90e4717a2f7118bc

  3. Modify the TestSession class
    1. ExpandISocialSession Members and ISocialSession2 members
    2. Modify GetActivities as shown below (changes in bold)

      C#

      public string GetActivities(string[] emailAddresses, DateTime startTime)
      FakePre-32b65d8736c849bf852211350e36e8d9-c7e26d42d62048979c30b9ab6a0efec5FakePre-1a765e62112144df826b26adcac76d3c-22b0ad4837914dbf8a920451b89fe060FakePre-6331958b920d4971b2123cd5e2c56825-3009de1afe8d4055b8402352c942a68aFakePre-8d39c2912eaf44a5929891fff77c0c95-4f2e4f1c4d1b400f94dfcac9015e6ed0FakePre-2d5388167a4f439698a78757703e879a-74945021acb24b48a501a6913d584f9cFakePre-c8d1afb2f30841998f03555652a70106-d3d77ea216364c4ca3f33fc25b5db682FakePre-6c78caa7aeee4b75aacf486bf514a757-fb1d4adc991d4b1d928c457ccac89f11FakePre-5ca853a59aa7486ba910c66cc3bbebec-89ec863e4b5a4e46a762c9512d9270edFakePre-0be17c4bfc03433b84906f8573266a45-0eb9aa05429443d7a2e9eb18ebfa1e30FakePre-65ef7c25504a42d781eb6d270586743b-ff279df8fa56436e8762cfa5132de0acFakePre-a0ab9e2aec214c2b807982353a7c8a30-e3d8558f813946aba4d59f3da59433e3FakePre-7d80fea0742349fb916182e3a036e174-d6dcd66d31b04ce99200d8944146cb31//string result = Properties.Resources.activityFeed;FakePre-54bfedc97bed4d5983b782e6eea79fcf-121b1871403e4c1485f6b05b844e0279FakePre-fbca076704344e4db1622d371eae92a9-d5d0e2c4168848e0891cb853b257a67fFakePre-b881d72bd55240058671acaf948ab578-18009f02b8604fb793a13ebc5778f2fcFakePre-45bc982ef0e04de888454e821f0cc7f3-4bf752d3b3bf45008a1a371273d9bd00

    3. Modify GetPeopleDetails as shown below (changes in bold)

      C#

      public string GetPeopleDetails(string personsAddresses)
      FakePre-d85b538372ab45a0900d266b83991277-dd9670c924b14f6bbedb08f5a8aadc2aFakePre-b04ebb038a95462d8ed8a4f08045408f-14d1d7eb41c04ac6859cbf7d9c9c7885//return Properties.Resources.friends; return SampleData.GetFriends(-1);FakePre-a800acae3dfd479d94298d172428d84c-e76c3ace4ea746bfaf8a65658ffd062d

Exercise 2 Verification

  1. Press F6 to build the solution.
  2. Make sure the SocialService that you launched in Exercise 2: Task 1 is up and running.
  3. Press F5 to debug the TestProvider
  4. In Outlook, press Ctrl + 6 to view the Folder List.
  5. Click on the contact folder named TestProvider. It should contain two contacts from when you initially ran TestProvider in Exercise 1.
  6. On the Add-Ins tab of the ribbon, click Sync Contacts. You should now see nine contacts in the TestProvider contacts folder.

    Figure 8

    TestProvider contacts folder