如何以Content-Type的形式返回响应:application / x-www-form-urlencoded;从WCF服务?

时间:2014-09-23 08:29:01

标签: c# wcf

花费大量时间最终使我的WCF服务接受Content-Type: application/x-www-form-urlencoded;请求(使用此处建议的流Best way to support "application/x-www-form-urlencoded" post data with WCF?

它终于有效了。

但是我得到了回复

Content-Type: application/xml; charset=utf-8
<string xmlns="http://schemas.microsoft.com/2003/10/Serialization/">result</string>

但我想要的是

Content-Type: application/x-www-form-urlencoded; charset=UTF-8
result

这可以在哪里设置/黑客攻击?

目前的方法如下:

[WebInvoke(UriTemplate = "generate_license", BodyStyle = WebMessageBodyStyle.Bare, Method = "POST")]
[OperationContract]
string GenerateLicense(Stream period);

1 个答案:

答案 0 :(得分:0)

好的,我似乎解决了这个问题:

public Stream GenerateLicense(Stream period)
        {
            Stream result = new MemoryStream();

            StreamWriter sw = new StreamWriter(result);
            sw.Write("LICENSE");
            sw.Flush();
            result.Position = 0;
            WebOperationContext.Current.OutgoingResponse.ContentType = "application/x-www-form-urlencoded; charset=UTF-8";
            return result;
        }