xml 在 WCF 休息服务响应中被更改 原因

xml gets altered in the wcf rest service response Why?

本文关键字:原因 响应 服务 WCF xml      更新时间:2023-09-26

Followin 是我的操作合约

[OperationContract]
[WebGet(ResponseFormat = WebMessageFormat.Xml,
        BodyStyle = WebMessageBodyStyle.Wrapped,
        UriTemplate = "/send?canvasbyte={imgbyte}")]
string sendresponse(string imgbyte);

以下是我的操作合同实现,我在这里返回一个相同的参数(字符串(

public string sendresponse(string imgbyte)
{
            return imgbyte;
}

正在使用HTML5客户端应用程序测试此服务,从其java脚本中,我正在发送xmlHttpRequest作为get方法传入 url 的值是画布绘图的数据 URL。

var canvas = document.getElementById('canvasid');
console.log(canvas.toDataURL());
var url = "http://myserverurl.com/ServiceImpl.svc/send?canvasbyte=" +          canvas.toDataURL().toString();
var xmlHttp = new XMLHttpRequest();
xmlHttp.onload = function () {
    var xmldocument = xmlHttp.responseText;
    console.log(xmlHttp.responseText);
};
xmlHttp.open("GET", url, true);
xmlHttp.send();

这是我的客户端代码,画布数据网址是一个大文本值。服务收到并返回相同的东西但是在这里,我对结果进行了一些更改。为什么??我想我在结果中缺少一些"+"号。

加号被浏览器解释为空格。

由于您使用的是 GET 方法,因此您的请求数据最终出现在查询字符串中(如果可以的话,最好使用 POST(。

当数据在查询字符串中时,服务器会自动将 + 更改为空格。

这是一个可能会有更多帮助的线程。

加号登录查询字符串

该代码存在太多问题。

首先,默认 IIS 配置不允许任何长度超过 2000 个字符的 URL。其次,get 需要传递转义值,因此,name=Files/John Doe变得name=Files%2FJohn+Doe不仅仅是 + 符号。

尝试将数据发布到您的方法中。