繁体   English   中英

在wcf服务上返回html格式而不是json或xml

[英]Return html format on wcf service instead of json or xml

我有运营合同:

[System.ServiceModel.Web.WebGet( UriTemplate = "c" , BodyStyle = WebMessageBodyStyle.Bare )]
[OperationContract]
string Connect ( );

我把它实现为:

    public string Connect ( )
    {
        return "<a href='someLingk' >Some link</a>";
    }

当我去那个链接时,我得到: 在此输入图像描述

如何将响应格式化为html? 甚至是纯文本。 我不想回复HTML或json ...

我知道我可以创建一个查询服务的网站,但我只想创建一个适用于任何浏览器的简单“类似于控制台”的应用程序......

返回流允许您返回原始字符串:

[System.ServiceModel.Web.WebGet( UriTemplate = "c" , BodyStyle = WebMessageBodyStyle.Bare )]
[OperationContract]
public System.IO.Stream Connect()
{
    string result = "<a href='someLingk' >Some link</a>";
    byte[] resultBytes = Encoding.UTF8.GetBytes(result);
    WebOperationContext.Current.OutgoingResponse.ContentType = "text/html";
    return new MemoryStream(resultBytes);
}

暂无
暂无

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

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