How can I make a subroutine out of this C# code?
<p>I have the following C# code and I have re-used it about 20x in my code. I can't figure out how to make it into a subroutine which would allow me to re-use it b/c of the type of object is based on a different class each time.</p>

<p>The purpose of the code is to send an HTTP request, gather the JSON response, then serialize JSON (using a DataContract) into a class for use in other areas.</p>

<p>Here's what I've got:</p>

<pre><code>    public static ResponseAttachmentIds MakeRequestAttachmentId(string requestUrl, string strToken)
    {
        try
        {
            HttpWebRequest request = WebRequest.Create(requestUrl) as HttpWebRequest;
            request.Headers["Authorization"] = "OAuth " + strToken;
            using (HttpWebResponse response = request.GetResponse() as HttpWebResponse)
            {
                if (response.StatusCode != HttpStatusCode.OK)
                    throw new Exception(String.Format(
                    "Server error (HTTP {0}: {1}).",
                    response.StatusCode,
                    response.StatusDescription));
                DataContractJsonSerializer jsonSerializer = new DataContractJsonSerializer(typeof(ResponseAttachmentIds));
                object objResponse = jsonSerializer.ReadObject(response.GetResponseStream());
                ResponseAttachmentIds jsonResponse = objResponse as ResponseAttachmentIds;
                response.Close();
                return jsonResponse;
            }
        }
        catch (Exception e)
        {
            System.Windows.Forms.MessageBox.Show(e.Message);
            return null;
        }

    }
</code></pre>

<p>The DataContract classes for this particular use are:</p>

<pre><code>public class ResponseAttachmentIds
{
    [DataMember(Name = "done")]
    public bool attachmentIds_done;
    [DataMember(Name = "records")]
    public List&lt;ResponseAttachmentId&gt; attachmentIds_records;
}
[DataContract]
public class ResponseAttachmentId
{
    [DataMember(Name = "Id")]
    public string attachmentId_strId { get; set; }
    [DataMember(Name = "Image_Attachment_Id__c")]
    public string attachmentId_strAttachmentId { get; set; }
}
</code></pre>

<p>The problem is that I've also got this same setup for about 20 different classes like <code>ResponseImages</code>, <code>ResponseProperties</code>, <code>ResponseProperty</code>, etc.</p>

<p>Any help?</p>