简体   繁体   中英

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? or even plain text. I don't want to get back html nor 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);
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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