我使用 VB.NET“WCF Rest Service Application”项目模板构建了一个非常简单的 Web 服务(这是一个不错的选择吗?)。我工作得很好,除了有
<string xmlns="http://schemas.microsoft.com/2003/10/Serialization/">
...
</string>
添加到我的答案中。
我已将返回值声明为 String :
<WebInvoke(UriTemplate:="member/login", Method:="POST",
responseformat:=WebMessageFormat.Json,
BodyStyle:=WebMessageBodyStyle.Bare)>
Public Function Create(data As IO.Stream) As String
Dim strData As String = New IO.StreamReader(data).ReadToEnd()
Dim UserAccessForm As LoginAccess = Me.getAnswer(strData)
Dim jsonAnswer As String
jsonAnswer = Newtonsoft.Json.JsonConvert.SerializeObject(UserAccessForm, Newtonsoft.Json.Formatting.None)
Return jsonAnswer
End Function
因此,不要将其作为答案:
{"logged":false,"userID":"0","message":"Empty body"}
我得到:
<string xmlns="http://schemas.microsoft.com/2003/10/Serialization/">
{"logged":false,"userID":"0","message":"Empty body"}
</string>
有什么办法可以避免我的字符串答案的这种不需要的序列化?