title: OBJECT Serialized using XML Serializer, when passed to the service using HTTPPOST, The values of the object are null or empty
body: <p><strong>This is my WCF REST OperationContract</strong></p>
  
  <pre><code> [OperationContract(Name = "SaveBasicInfoObjectById")]
       [WebInvoke(Method = "POST",
            ResponseFormat = WebMessageFormat.Xml,
            RequestFormat = WebMessageFormat.Xml,
           BodyStyle = WebMessageBodyStyle.Bare,
           UriTemplate = "Core/SaveBasicInfoObjectById?ID={ID}")]
       List&lt;Response&gt; SaveBasicInfoObjectById(string ID, BasicClass basicClass);
  </code></pre>
  
  <p><strong>This is my client code</strong></p>
  
  <pre><code>  string ID= "123";
  
    MyService.BasicClass basicClass = new MyService.BasicClass();
  
  
    string sErrorMsg = "";
    string sResponseStatus = "";
  string URLString = "http://localhost:59133/MyService.svc/Core/SaveBasicInfoObjectById?ID=" + ID;
  
  
  basicClass.FirstName = txt_Fname.Text.Trim();
  basicClass.Lastname = txt_Lname.Text.Trim();
  
  var paramContent = Serialize(basicClass);
  
  CreateWebRequest(URLString, paramContent.ToString());
  </code></pre>
  
  <p><strong>This is the Serialize Method</strong></p>
  
  <pre><code>    public static string Serialize&lt;T&gt;(T obj)
      {
  
          var serializer = new System.Xml.Serialization.XmlSerializer(obj.GetType());
          var ms = new MemoryStream();
          serializer.Serialize(ms, obj);
          string retVal = Encoding.Default.GetString(ms.ToArray());
          ms.Dispose();
          return retVal;
  
      }
  </code></pre>
  
  <p><strong>This Is The CreateWebRequest method</strong></p>
  
  <pre><code>    private string CreateWebRequest(string endPoint, string paramContent)
      {
          string result = string.Empty;
  
          byte[] buffer = Encoding.UTF8.GetBytes(paramContent);
          var myHttpWebRequest = (HttpWebRequest)WebRequest.Create(endPoint);
  
          myHttpWebRequest.Method = "POST";
          myHttpWebRequest.ContentLength = buffer.Length;
          myHttpWebRequest.ContentType = "text/xml";
  
          using (var request = myHttpWebRequest.GetRequestStream())
          {
              request.Write(buffer, 0, buffer.Length);
              request.Close();
          }
  
          var myHttpWebResponse = (HttpWebResponse)myHttpWebRequest.GetResponse();
          using (var reader = new StreamReader(myHttpWebResponse.GetResponseStream(), Encoding.UTF8))
          {
              result = reader.ReadToEnd();
              myHttpWebResponse.Close();
          }
  
  
          return result;
      }
  </code></pre>
  
  <p>*<em>The problem here that i am facing is the Object is serialized in the following format, and when the breakpoint is hit at the service the object values are empty i.e firstname = "" and lastname = "" *</em></p>
  
  <pre><code>&lt;?xml version="1.0"?&gt;
   &lt;BasicClass xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" ID="0"&gt;
  &lt;FirstName xmlns="http://tempuri.org/"&gt;James&lt;/FirstName&gt;
  &lt;Lastname xmlns="http://tempuri.org/"&gt;Kravis&lt;/Lastname&gt;
  &lt;/BasicClass&gt;
  </code></pre>
  
  <p>Can any one advice why this is happening?</p>
  
  <p>I have now replaced the tempuri namespace against the firstname and lastname element as "" or empty, Now this working and the values from the client are now recieved at the service</p>
  
  <p><strong>Following is the updated code for serialize method</strong> </p>
  
  <pre><code>public  string Serialize&lt;T&gt;(T obj)
      {
          //System.Xml.Serialization.XmlSerializer x = new System.Xml.Serialization.XmlSerializer(p.GetType());
          var serializer = new System.Xml.Serialization.XmlSerializer(obj.GetType());
          var ms = new MemoryStream();
          serializer.Serialize(ms, obj);
          string retVal = Encoding.Default.GetString(ms.ToArray());
          ms.Dispose();
          return retVal.Replace("xmlns=\"http://tempuri.org/\"", "");
      }
  </code></pre>
  
  <p>** Update to above code **</p>
  
  <pre><code>public  string Serialize&lt;T&gt;(T obj)
      {
          var serializer = new System.Xml.Serialization.XmlSerializer(obj.GetType());
          var ms = new MemoryStream();
          serializer.Serialize(ms, obj);
          string retVal = Encoding.Default.GetString(ms.ToArray());
          ms.Dispose();
          return retVal;
      }
  </code></pre>
  
  <p>** Got Rid of the replace and found the way to stop the default namespace being added to the elements **</p>
  
  <pre><code>public class BasicClass
  {
      [XmlElement(Namespace="")]//add namespace as ""
      public string Firstname{get;set;}
  
      [XmlElement(Namespace="")]//add namespace as ""
      public string Lastname{get;set;}
  }
  </code></pre>
  
  <p><strong>By Doing as above i am able to remove the default namespace and no need of replace</strong></p>
  
  <pre><code>&lt;?xml version="1.0"?&gt;
   &lt;BasicClass xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" ID="0"&gt;
  &lt;FirstName&gt;James&lt;/FirstName&gt;
  &lt;Lastname&gt;Kravis&lt;/Lastname&gt;
  &lt;/BasicClass&gt;
  </code></pre>