我正在努力解决这个问题,请帮忙。我必须调用REST WCF服务来传递一个对象。 你能告诉我一个代码,看看我试图发送给服务的xml格式。
Dim request As WebRequest
request = WebRequest.Create("http://localhost:1143/ServiceHost.svc/REST/GetResponseCode")
request.Method = "POST"
request.ContentType = "application/xml; charset=utf-8"
Dim dcs As New DataContractSerializer(GetType(transaction))
Dim xdw As XmlDictionaryWriter = _
XmlDictionaryWriter.CreateTextWriter(request.GetRequestStream(), Encoding.UTF8)
dcs.WriteObject(xdw, tran)
Dim res As WebResponse = request.GetResponse()
答案 0 :(得分:0)
好。终于找到了解决方案。这是我的代码中的一个错误,消息传输没有问题。错误地,我在上面的代码中将Class作为参数传递给GetType。
Dim dcs As New DataContractSerializer(tran.GetType())
此外,我最后关闭了XmlDictionaryWriter,否则将发生'Request.GetResponse()'超时。