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

Ton*_*Nam 11 c# wcf webget

我有运营合同:

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

我把它实现为:

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

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

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

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

sro*_*oes 32

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

[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);
}
Run Code Online (Sandbox Code Playgroud)