简体   繁体   English

WCF REST服务呼叫-400错误的请求

[英]WCF REST Service call - 400 bad request

I am struggling to resolve this issue, pls help. 请帮助我,我正在努力解决这个问题。 I have to call REST WCF service to pass an object. 我必须调用REST WCF服务来传递对象。 Can you tell me a code to see xml format that I am trying to send to service. 您能告诉我一个代码,以查看我尝试发送给服务的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()

Well. 好。 At last found solution. 最后找到解决方案。 It's a bug in my code and there are no issues with messaging transport. 这是我的代码中的错误,消息传递没有问题。 Mistakenly, I have passed Class as a parameter in GetType in above code. 错误地,我在上面的代码中将Class作为参数传递给GetType。

Dim dcs As New DataContractSerializer(tran.GetType())

Also I have closed XmlDictionaryWriter at the end, otherwise 'Request.GetResponse()' timeout will happens. 我也关闭了XmlDictionaryWriter在最后,否则'Request.GetResponse()'超时将发生。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM