title: WCF REST adding data using POST or PUT 400 Bad Request
body: <p>HI
  How do i add data using wcf rest architecture.
  I dont want to use the channelfactory to call my method. 
  Something similar to the webrequest and webresponse used for GET. Something similar to the ajax WebServiceProxy restInvoke
  Or do i always have to use the Webchannelfactory implementation</p>
  
  <p>I am getting a 400 BAD request by using the following</p>
  
  <p>Dim url As String = "<a href="http://localhost:4475/Service.svc/Entity/Add" rel="nofollow noreferrer">http://localhost:4475/Service.svc/Entity/Add</a>"
          Dim req As WebRequest = WebRequest.Create(url)
          req.Method = "POST"
          req.ContentType = "application/xml; charset=utf-8"
          req.Timeout = 30000
          req.Headers.Add("SOAPAction", url)</p>
  
  <pre><code>    Dim xEle As XElement
      xEle = &lt;Entity xmlns:i="http://www.w3.org/2001/XMLSchema-instance"&gt;
                   &lt;Name&gt;Entity1&lt;/Name&gt;
               &lt;/Entity&gt;
  
      Dim sXML As String = xEle .Value
      req.ContentLength = sXML.Length
      Dim sw As New System.IO.StreamWriter(req.GetRequestStream())
      sw.Write(sXML)
      sw.Close()
  
      Dim res as HttpWebResponse = req.GetResponse()
  </code></pre>
  
  <hr>
  
  <pre><code>    Sercice Contract is as follows
  
     &lt;OperationContract()&gt; _
     &lt;WebInvoke(Method:="PUT", UriTemplate:="Entity/Add")&gt; _
     Function AddEntity(ByVal e1 As Entity)
  </code></pre>
  
  <hr>
  
  <pre><code>     DataContract is as follows
  
      &lt;Serializable()&gt; _
      &lt;DataContract()&gt; _
      Public Class Entity
        private m_Name as String
       &lt;DataMember()&gt; _
        Public Property Name() As String
        Get
          Return m_Name
        End Get
        Set(ByVal value As String)
          m_Name = value
        End Set
        End Property
      End Class
  </code></pre>
  
  <p>thanks</p>