简体   繁体   English

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

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

I have the operation contract: 我有运营合同:

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

and I have it implemented as: 我把它实现为:

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

when I go to that link I get: 当我去那个链接时,我得到: 在此输入图像描述

how can I format the response as html? 如何将响应格式化为html? or even plain text. 甚至是纯文本。 I don't want to get back html nor json... 我不想回复HTML或json ...

I know I can create a website that queries the service but I just want to create a simple "Console like" application that works on any browser... 我知道我可以创建一个查询服务的网站,但我只想创建一个适用于任何浏览器的简单“类似于控制台”的应用程序......

Returning a stream allows you to return a raw string: 返回流允许您返回原始字符串:

[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