title: How to send xml via post to wcf service
body: <p>I got a code which post xml to wcf service. Here is the full code</p>
  
  <p>1) WCF Service Interface</p>
  
  <pre><code>[OperationContract]
  [WebInvoke(Method = "POST",
      UriTemplate = "GetData",
      RequestFormat = WebMessageFormat.Xml,
      BodyStyle = WebMessageBodyStyle.Bare)]
  string GetData(DataRequest parameter);
  </code></pre>
  
  <p>2) WCF Service Implementation</p>
  
  <pre><code>public string GetData(DataRequest parameter)
  {
      //Do stuff
      return "your data here";
  }
  </code></pre>
  
  <p>3) Data Contract in your WCF service (In this case it's DataRequest)</p>
  
  <pre><code>[DataContract(Namespace = "YourNamespaceHere")]
  public class DataRequest
  {
      [DataMember]
      public string ID{ get; set; }
      [DataMember]
      public string Data{ get; set; }
  }
  </code></pre>
  
  <p>4) Client sending the data must have the data constructed properly! (C# console app in this case)</p>
  
  <pre><code>static void Main(string[] args)
  {
      ASCIIEncoding encoding = new ASCIIEncoding();
      string SampleXml = "&lt;DataRequest xmlns=\"YourNamespaceHere\"&gt;" +
                                      "&lt;ID&gt;" +
                                      yourIDVariable +
                                      "&lt;/ID&gt;" +
                                      "&lt;Data&gt;" +
                                      yourDataVariable +
                                      "&lt;/Data&gt;" +
                                  "&lt;/DataRequest&gt;";
  
      string postData = SampleXml.ToString();
      byte[] data = encoding.GetBytes(postData);
  
      string url = "http://localhost:62810/MyService.svc/GetData";
  
      string strResult = string.Empty;
  
      // declare httpwebrequet wrt url defined above
      HttpWebRequest webrequest = (HttpWebRequest)WebRequest.Create(url);
      // set method as post
      webrequest.Method = "POST";
      // set content type
      webrequest.ContentType = "application/xml";
      // set content length
      webrequest.ContentLength = data.Length;
      // get stream data out of webrequest object
      Stream newStream = webrequest.GetRequestStream();
      newStream.Write(data, 0, data.Length);
      newStream.Close();
  
      //Gets the response
      WebResponse response = webrequest.GetResponse();
      //Writes the Response
      Stream responseStream = response.GetResponseStream();
  
      StreamReader sr = new StreamReader(responseStream);
      string s = sr.ReadToEnd();
  
      return s;
  }
  </code></pre>
  
  <p>My question is that if GetData() function expect two or more parameter then how could I supply value to GetData()</p>
  
  <pre><code>public string GetData(string xml1,string xml2)
  {
       //Do stuff return "your data here";
  }
  </code></pre>
  
  <p>so please guide me how to pass two xml data to <code>GetData()</code> function ? </p>