【发布时间】:2010-12-10 17:44:31
【问题描述】:
你好 如何使用 wcf REST 架构添加数据。 我不想使用 channelfactory 来调用我的方法。 类似于用于 GET 的 webrequest 和 webresponse。类似于 ajax WebServiceProxy restInvoke 的东西 还是我总是必须使用 Webchannelfactory 实现
我通过以下方式收到 400 BAD 请求
将网址调暗为字符串 = "http://localhost:4475/Service.svc/Entity/Add" Dim req As WebRequest = WebRequest.Create(url) req.Method = "POST" req.ContentType = "应用程序/xml; charset=utf-8" 请求超时 = 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
谢谢
【问题讨论】: