Home > View Post

Part I. Designing the Feedback Contract

Earlier I introduced a series of posts that would show the interesting bits of the implementation of a feedback service. This is part I.

First thing we need to build our Feedback service is our contract. I'm keeping the example simple here - you can add as much to this as you like. We're going to collect the following data:

  • Feedback Type - Positive or Negative.
  • Comments - the users comments.
  • E-mail Address - in case we need to reply. We need to be clear that we won't share this with anyone.
  • Screenshot - grab of the screen
So now we can design our DataContract for our WCF service:

[DataContract(Namespace="urn:schemas-thejoyofcode-com:feedback:2007-08")]
public class Feedback
{
    private FeedbackType _feedbackType;

    [DataMember(IsRequired=true)]
    public FeedbackType FeedbackType
    {
        get { return _feedbackType; }
        set { _feedbackType = value; }
    }
    
    private string _comments;

    [DataMember]
    public string Comments
    {
        get { return _comments; }
        set { _comments = value; }
    }
    
    private string _emailAddress;

    [DataMember]
    public string EmailAddress
    {
        get { return _emailAddress; }
        set { _emailAddress = value; }
    }

    private byte[] _screenGrab;

    [DataMember]
    public byte[] ScreenGrab
    {
        get { return _screenGrab; }
        set { _screenGrab = value; }
    }
}

Notice that we simply specify the screen grab as a byte array. Easy peasy.

Here's the FeedbackType enum.

[DataContract(Namespace=Namespaces.FeedbackService)]
public enum FeedbackType
{
    [EnumMember]
    NotSpecified,
    [EnumMember]
    Positive,
    [EnumMember]
    Negative,
}

Next, we need a ServiceContract that allows us to submit our feedback. As usual, we'll use an interface to declare this.

[ServiceContract(Namespace="urn:schemas-thejoyofcode-com:feedback:2007-08")]
[ServiceKnownType(typeof(FeedbackType))]
public interface ISendFeedbackContract
{
    [OperationContract(IsOneWay=true)]
    void SendFeedback(Feedback feedback);
}

Note how we've flagged SendFeedback as a one-way operation? No need to keep the client waiting if we're reasonably confident the package has been delivered.

Finally we need an implementation of the service that writes this to a database.

public class FeedbackService : ISendFeedbackContract
{
    public void SendFeedback(Feedback feedback)
    {
        try
        {
            FeedbackDal.InsertFeedback(feedback);
        }
        catch (Exception exc)
        {
            // TODO Don't forget your logging and exception shielding etc here
        }
    }
}
    
We'll look at the Dal (Data Access Layer) in the next post. Let's focus on getting the service up for now by choosing a host... IIS. Yup we want to use plain old HTTP over port 80 for this service to make it as accessible as possible to all users so the hosting choice is easy.

We'll need a Feedback.svc file in our web app folder that looks like this:

<%@ServiceHost Service="YourNamespace.FeedbackService" %>
<%@Assembly Name="YourAssembly"%>

And that's it. Ooh, except for the web.config and all the settings our service will need:

<system.serviceModel>
    <services>
        <service name="YourNamespace.FeedbackService">
            <endpoint contract="YourNamespace.ISendFeedbackContract" binding="basicHttpBinding" bindingConfiguration="mtomConfig"/>
        </service>
    </services>
    <bindings>
        <basicHttpBinding>
            <binding name="mtomConfig" messageEncoding="Mtom" maxBufferSize="5000000" maxReceivedMessageSize="5000000">
                <readerQuotas maxArrayLength="5000000"/>
                <security mode="None"/>
            </binding>
        </basicHttpBinding>
    </bindings>
</system.serviceModel>

That's probably the bare minimum to get this working. Notice how we've gone for MTOM encoding and increased the maxBufferSize, maxReceivedMessageSize and maxArrayLength to 5,000,000. This will prevent problems when uploading our screengrab.

Next, we'll look at how we write the data to the database.

Part II. Storing the Feedback Data

Tags: ASP.NET

 
Josh Post By Josh Twist
8:21 AM
06 Aug 2007

» Next Post: Part II. Storing the Feedback Data
« Previous Post: Feedback for your Smart Client

Comments are closed for this post.

© 2005 - 2017 Josh Twist - All Rights Reserved.