title: Passing Parameters as Xml to a Stored Procedure
body: <p>I've got a requirement to pass parameters as Xml to my stored procedures.</p>
  
  <p>I have a WCF service in the middle tier that makes calls to my data layer which in turn forwards the request to the appropriate stored procedure.</p>
  
  <p>The design is that the WCF service is responsible for building the Xml to pass to the Repository.</p>
  
  <p>I'm just wondering whether to keep control of what parameters are contained within the Xml in the middle tier or use a Dictionary built up by the client which I then convert to Xml in the middle tier?</p>
  
  <p>At the moment I've gone for the latter - for example:</p>
  
  <pre><code> public TestQueryResponseMessage TestQuery(TestQueryRequestMessage message)
   {
          var result = Repository.ExecuteQuery("TestQuery", ParamsToXml(message.Body.Params));
  
          return new TestQueryResponseMessage
          {
              Body = new TestQueryResponse
              {
                  TopicItems = result;
              }
          }
      }
  
  
  private string ParamsToXml(Dictionary&lt;string, string&gt; nvc)
  {
          //TODO: Refactor
          StringBuilder sb = new StringBuilder();
  
          sb.Append("&lt;params&gt;");
          foreach (KeyValuePair&lt;string, string&gt; param in nvc)
          {
              sb.Append("&lt;param&gt;");
              sb.Append("&lt;" + param.Key + "&gt;");
              sb.Append(param.Value);
              sb.Append("&lt;/" + param.Key + "&gt;");
              sb.Append("&lt;/param&gt;");
          }
          sb.Append("&lt;/params&gt;");
  
          return sb.ToString();
  }
  </code></pre>
  
  <p>However I might need to do it the first way. E.g.</p>
  
  <pre><code>public TestQueryResponseMessage TestQuery(TestQueryRequestMessage message)
  {
         string xml = string.Format("&lt;params&gt;&lt;TestParameter&gt;{0}&lt;/TestParameter&gt;&lt;/params&gt;",message.Body.TestParameter)
  
         var result = Repository.ExecuteQuery("TestQuery", xml);
  
        return new TestQueryResponseMessage
        {
            Body = new TestQueryResponse
            {
                      TopicItems = result;
            }
        }
  }
  </code></pre>
  
  <p>What does the hivemind recommend?</p>