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:

public class Feedback
    private FeedbackType _feedbackType;

    public FeedbackType FeedbackType
        get { return _feedbackType; }
        set { _feedbackType = value; }
    private string _comments;

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

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

    private byte[] _screenGrab;

    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.

public enum FeedbackType

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

public interface ISendFeedbackContract
    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)
        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:

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

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


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 - 2022 Josh Twist - All Rights Reserved.