WCF REST adding data using POST or PUT 400 Bad Request

Posted by user55474 on Stack Overflow See other posts from Stack Overflow or by user55474
Published on 2009-10-28T03:22:23Z Indexed on 2010/12/21 5:54 UTC
Read the original article Hit count: 259

Filed under:
|

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

I am getting a 400 BAD request by using the following

Dim url As String = "http://localhost:4475/Service.svc/Entity/Add" 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)

    Dim xEle As XElement
    xEle = <Entity xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
                 <Name>Entity1</Name>
             </Entity>

    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()


    Sercice Contract is as follows

   <OperationContract()> _
   <WebInvoke(Method:="PUT", UriTemplate:="Entity/Add")> _
   Function AddEntity(ByVal e1 As Entity)


     DataContract is as follows

    <Serializable()> _
    <DataContract()> _
    Public Class Entity
      private m_Name as String
     <DataMember()> _
      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

thanks

© Stack Overflow or respective owner

Related posts about wcf

Related posts about rest