【发布时间】:2015-03-04 15:53:09
【问题描述】:
以下是我的服务合同
[OperationContract]
[WebInvoke(Method = "POST", UriTemplate = "/SavePrint?seq={seq}", BodyStyle = WebMessageBodyStyle.Bare)]
bool SavePrint(int seq, string print_lines);
字符串总是超过 3000 个字符,所以我不能在 URL 中传递它。
我正在尝试使用 WebClient 类上传。
WebClient client = new WebClient();
client.Headers["Content-type"] = "application/xml";
client.UploadString(baseURLTxtBox.Text + "/SavePrint?seq=1", LongStringHere);
当我尝试使用 WebClient 类的 UploadString 方法传递它时,服务失败并出现错误 There was an error checking start element of object of type System.String. The data at the root level is invalid. Line 1, position 1.
我假设是因为它被认为是 XML,所以我将我的字符串包装在 XML 中
<string xmlns="">LongStringHere</string>
然后我得到错误
无法使用根名称“字符串”和根名称空间“”反序列化 XML 正文(对于操作“SavePrint”和合同(“IPrintAPI”, 'http://tempuri.org/')) 使用 DataContractSerializer。确保 将 XML 对应的类型添加到已知类型集合中 服务。
我不知道我应该如何将字符串添加到已知类型集合中。
【问题讨论】:
标签: c# wcf rest serialization http-post