To read a user profile in the Profile Manager, perform the following steps:
- Add the following using directives to your code:
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading;
using Microsoft.ConnectedServices.Contracts.ProfileManager;
using Microsoft.ConnectedServices.Sdk.Messaging;
using Microsoft.Web.Services3.Messaging;
using Microsoft.ConnectedServices.Sdk;
using Microsoft.ConnectedServices.Sdk.Client;
using Microsoft.Web.Services3.Addressing;
using System.Net;
using Microsoft.ConnectedServices.Sdk.Security.Tokens;
using Microsoft.Web.Services3;
using Microsoft.ConnectedServices.Sdk.Rdf;
using Microsoft.ConnectedServices.Sdk.Eventing;
using System.Xml;
using Microsoft.Web.Services3.Design;
using System.Diagnostics;
- Define a namespace for the Profile Manager client:
namespace ProfileManagerClientNamespace
{
// Change ProfileManagerClientNamespace to a namespace that meets naming requirements.
}
- Declare a class the inherits from the CsfService class and implements the IProfileManagerResponse interface:
public class ProfileManagerClient : CsfService, IProfileManagerResponse
{
// Change ProfileManagerClient to a name that reflects one of your choice.
}
- Declare variables:
private Uri serviceUri;
private Uri clientUri;
private ReadProfileResponse rpResponse;
private int timeOut;
private SoapFaultException faultException;
private Dictionary waitHandles;
- Assign the URI of the Profile Manager Web service to the serviceUri variable. Change CSFHost to the name of the server on which CSF is being hosted.
serviceUri = new Uri(
"http://CSFHost/pmsvc/ProfileManager.ashx");
- Assign the URI of this client service to the clientUri variable. Change URI of the Web service client to the URI location of the current Web service client.
serviceUri = new Uri(
"URI of Web service client");
- Assign an integer value to the timeOut variable.
timeOut = 180000; // Five minutes. Change this as needed.
- Declare a method that sends the new profile information to the Profile Manager Web service:
private EventWaitHandle SendMessage(string action, object content)
{
Message msg = Message.CreateMessage(action, serviceUri, content);
// Add any credential and policy information required
// by the Profile Manager.
msg.Header.Addressing.ReplyTo = new CsfSdk.Addressing.EndpointReference(clientUri);
MessageSender sender = new MessageSender();
// Set any policy required by the Profile Manager by
// using MessageSender.SetPolicy method.
sender.SendAsync(msg);
faultException = null;
EventWaitHandle handle = new EventWaitHandle(
false, EventResetMode.AutoReset);
waitHandles.Add(msg.Header.Addressing.MessageID.ToString(), handle);
return handle;
}
- Declare a method that creates a SPARQL query, uses it to compose the ReadProfileRequest, and then uses the method that was defined in step 9 to send the read request to the Profile Manager Web service:
public void ReadProfile()
{
string sparqlQuery =
@"PREFIX ex: <http://example.org/stuff/1.0/>
CONSTRUCT {
<http://www.contoso.com/csf/pm/syedabbas> ex:fullName ?Name
}
WHERE {
<http://www.contoso.com/csf/pm/syedabbas> ex:fullName ?Name
}
";
ReadProfileRequest request = new ReadProfileRequest();
request.Query = sparqlQuery;
EventWaitHandle handle = SendMessage(
ProfileManagerActions.ReadProfileRequest, request);
if (!handle.WaitOne(timeOut, false))
{
Assert.Fail("Response not received in time");
return;
}
if (faultException != null)
{
throw faultException;
}
Assert.IsFalse(
rpResponse == null,
"No response received"
);
}
- Implement the methods required by the IProfileManagerResponse interface, such as the CreateProfileResponseHandler, ReadProfileResponseHandler, UpdateProfileResponseHandler, and DeleteProfileResponseHandler methods. This example shows an implementation of the ReadProfileResponseHandler method:
public void ReadProfileResponseHandler(ReadProfileResponse response)
{
rpResponse = response;
// Add application specific implementation here.
}
Example
The following example code shows a method that creates and populates a ReadProfileRequest and a second method that sends the request to the Profile Manager:
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading;
using Microsoft.ConnectedServices.Contracts.ProfileManager;
using Microsoft.ConnectedServices.Sdk.Messaging;
using Microsoft.Web.Services3.Messaging;
using Microsoft.ConnectedServices.Sdk;
using Microsoft.ConnectedServices.Sdk.Client;
using Microsoft.Web.Services3.Addressing;
using System.Net;
using Microsoft.ConnectedServices.Sdk.Security.Tokens;
using Microsoft.Web.Services3;
using Microsoft.ConnectedServices.Sdk.Rdf;
using Microsoft.ConnectedServices.Sdk.Eventing;
using System.Xml;
using Microsoft.Web.Services3.Design;
using System.Diagnostics;
namespace ProfileManagerClientNamespace
{
// Change ProfileManagerClientNamespace to a name that reflects your naming conventions.
public class ProfileManagerClient : CsfService, IProfileManagerResponse
{
// Change ProfileManagerClient to a name that reflects one of your choice.
private string rdfXml;
private Uri serviceUri;
private Uri clientUri;
private CreateProfileResponse cpResponse;
private int timeOut;
private SoapFaultException faultException;
private Dictionary waitHandles;
public ProfileManagerClient()
{
serviceUri = new Uri(
"http://CSFHost/pmsvc/ProfileManager.ashx");
clientUri = new Uri(
"URI of Web service client");
timeOut = 180000; // Five minutes. Change this as needed.
}
public void ReadProfile()
{
string sparqlQuery =
@"PREFIX ex: <http://example.org/stuff/1.0/>
CONSTRUCT {
<http://www.contoso.com/csf/pm/syedabbas> ex:fullName ?Name
}
WHERE {
<http://www.contoso.com/csf/pm/syedabbas> ex:fullName ?Name
}
";
ReadProfileRequest request = new ReadProfileRequest();
request.Query = sparqlQuery;
EventWaitHandle handle = SendMessage(
ProfileManagerActions.ReadProfileRequest, request);
if (!handle.WaitOne(timeOut, false))
{
Assert.Fail("Response not received in time");
return;
}
if (faultException != null)
{
throw faultException;
}
Assert.IsFalse(
rpResponse == null,
"No response received"
);
}
private EventWaitHandle SendMessage(string action, object content)
{
Message msg = Message.CreateMessage(action, serviceUri, content);
// Add any credential and policy information required
// by the Profile Manager.
msg.Header.Addressing.ReplyTo = new CsfSdk.Addressing.EndpointReference(clientUri);
MessageSender sender = new MessageSender();
// Set any policy required by the Profile Manager by
// using MessageSender.SetPolicy method.
sender.SendAsync(msg);
faultException = null;
EventWaitHandle handle = new EventWaitHandle(
false, EventResetMode.AutoReset);
waitHandles.Add(msg.Header.Addressing.MessageID.ToString(), handle);
return handle;
}
public void ReadProfileResponseHandler(ReadProfileResponse response)
{
rpResponse = response;
// Add application specific handler implementation here.
}
// Also implement the CreateProfileResponseHandler,
// UpdateProfileResponseHandler,
// and DeleteProfileResponseHandler methods.
. . . . . .
}
}
See Also