HI 如何使用wcf rest架構添加數據。 我不想使用channelfactory來調用我的方法。 與用於GET的webrequest和webresponse類似。同樣的事情也給Ajax WebServiceProxy restInvoke 還是我總是要使用Webchannelfactory實施WCF REST使用POST或PUT 400錯誤請求添加數據
我通過以下
昏暗的URL的String =「http://localhost:4475/Service.svc/Entity/Add」 昏暗REQ作爲WebRequest的得到一個400錯誤的請求=「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
感謝