views:

57

answers:

0

A little background: I'm using the WCF REST Starter kit, and I'm creating a wrapper for a specific API I'm consuming. There are common query string parameters that I need to pass whenever I hit any of the exposed methods, such as an API key.

To me, it would be easier to make such common parameters a part of the wrapper class. Then I could add the parameters specific to each method. For example:

public sealed class WrapperClass: HttpClient
{
    private string ServiceEndPoint;
    private string ServiceApiKey;
    private string ReturnFormat;

    private HttpQueryString StandardQueryString;

    public WrapperClass (string endpoint, string apiKey, string format)
        : base(endpoint)
    {
        ServiceEndPoint= endpoint;
        ServiceApiKey= apiKey;
        ReturnFormat= format;

        StandardQueryString = new HttpQueryString
        {
            { "key", ServiceApiKey},
            { "format", ReturnFormat}
        };
    }

    public string Method1(string someParam)
    {
        var query = new HttpQueryString();

        // here I want to copy the values already in StandardQueryString, and then append any params specific to this method.
        // psuedo code:
        query.CopyValues(StandardQueryString);
        query.Add("methodSpecificParam", someParam);

        using (var response = this.Get(new Uri("ServiceMethod1/", UriKind.Relative), query))
        {
            response.EnsureStatusIsSuccessful();
            // blah blah parse the response and return a string
        }
    }
}

How do I copy the parameters between two HttpQueryString objects?