Retrieving Agent’s Sign-in Information in RGS

Animated by a recent comment I decided to give some more insight into the Agent Sign-in logic of the Response Group Service of Office Communications Server 2007 R2.

We keep the sign-in states of agents in formal agent groups in a dedicated table called ‘AgentGroupSignInStates’ in the backend database (called ‘acddyn’) for each pool. The table is kept very simple. It consists only of three fields:

  • AgentId (uniqueidentifier)
  • GroupId (uniqueidentifier)
  • State (tinyint)

The first two fields, AgentId and GroupId, make up the primary key for the table, so they have to be unique. In other words, an agent can only have one sign-in state for every group he’s a member of. The State field indicates the current sign-in state for the agent with the given AgentId in the group with the given GroupId. A value of 0 means that the agent is not signed in, 1 means that the agent is signed in. If a record does not exist for an agent in a formal group, then the agent has never signed in yet (so he’s signed out). The AgentId and GroupId values should match the values of existing agents and groups in the RGS system (in WMI), though this is not enforced.

You should not modify records in the ‘AgentGroupSignInStates’ table, because the table is only kept as a reference in case of data-loss in the MatchMaking component of the Response Group Service. However, MatchMaking always keeps this table up-to-date, so reading from it should give you the most recent view on the sign-in states of the agents.

Migrating ASP.NET Web Services to WCF

I recently had to migrate a common ASP.NET web service over to WCF, making sure that clients of the former would still be able to use the latter. There were a couple of things I stumbled across, so I am blogging about the minimal steps I had to perform to get clients of the old ASP.NET web service running with the new WCF one. Let’s use the following simple ASP.NET web service for this tiny tutorial.

[WebService(Namespace = "")]
public class MathAddService : WebService
    public int Add(int x, int y)
        // Let's ignore overflows here ;-)
        return x + y;

The first thing we need to do is create a new interface which offers the same methods as the web service did and mark it as a service contract. This is required because the WCF endpoints are contract based, i.e. they need such an interface. So we extract the public web service interface of the MathAddService class and decorate it with the WCF attributes:

[ServiceContract(Namespace = "")]
public interface IMathAddService
    [OperationContract(Action = "")]
    int Add(int x, int y);

The ServiceContract attribute tells WCF to use the same namespace for the web service as ASP.NET did. If you don’t do this, your clients will not be able to use the migrated service because the namespaces don’t match. The XmlSerializerFormat attribute is used to make sure that WCF uses the standard SOAP format for messages. If you don’t specify this, your clients will likely see strange error messages of mismatching operations / messages. Then, for each method you exposed in the former web service, you need to add the exact same signature here, plus make sure that the OperationContract attribute for each method has the Action property set to ‘/’ . Without this, you’ll get another set of exceptions like ‘operation not defined’.

Now the next step is to implement this interface in a class, but we basically already have this in the former MathAddService class. So we just adapt the class’ definition as follows.

[WebService(Namespace = "")]
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
[ServiceBehavior(Namespace = "")]
public class MathAddService : WebService, IMathAddService
    public int Add(int x, int y)
        // Let's ignore overflows here ;-)
        return x + y;

As you can see, we’re also adding two new attributes. AspNetCompatibilityRequirements are used to make sure that the new WCF service is really capable of serving old clients. The ServiceBehavior attribute is used to make sure that the WCF hosted service really uses the correct namespace, i.e. the same as the old ASP.NET service used. By the way, you should find all the additional attributes in the System.ServiceModel and System.ServiceModel.Activation namespaces (from the System.ServiceModel assembly).

Now lets get to the configuration of endpoints and bindings for the web service. The following block shows you the new sections in the web.config file for the virtual directory which hosts the WCF service.

<configuration xmlns="">
        <!-- ... -->
        <serviceHostingEnvironment aspNetCompatibilityEnabled="true" />
            <service name="MathAddService" behaviorConfiguration="MathAddServiceBehavior">
                <endpoint address=""
                <binding name="httpsIwa">
                    <security mode="Transport">
                        <transport clientCredentialType="Windows" />
                <behavior name="MathAddServiceBehavior">
                    <serviceMetadata httpsGetEnabled="true" />
                    <serviceDebug httpsHelpPageEnabled="true" includeExceptionDetailInFaults="true" />

As you can see on lines 19 and 20, we are using HTTPS and IWA for this particular binding, but you should of course make it the same as you had for your ASP.NET service. If you served all requests without HTTP based authentication and without SSL/TLS, then you should stick to that so you don’t break your clients :). You have to make sure that you are offering at least one basicHttpBinding, because that’s what closest matches the ASP.NET SOAP interface.

Finally, we add a new file called ‘MathAddService.svc’ in the virtual directory on IIS with the following contents.

<%@ ServiceHost Service="MathAddService" %>

This will use the implementation of the MathAddService class to serve the request for the IMathAddService interface. Of course your clients will have to be updated to use the new URL now (or you can try a 302 redirect but depending on the client’s policies, this may fail). In case your requests to the new SVC file produce strange results (or send you back the above contents of the file), in the IIS administrative tools make sure that the .svc extension is mapped properly. If it isn’t, you can run the aspnet_regiis.exe tool from the .NET framework to get that done.