Return html format on wcf service instead of json or xml
Asked Answered
L

1

14

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: enter image description here

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...

Lozano answered 6/12, 2012 at 22:31 Comment(0)
O
35

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);
}
Ovotestis answered 6/12, 2012 at 22:40 Comment(1)
I find that for long HTML files some of the content is duplicated in the output.Gerger

© 2022 - 2024 — McMap. All rights reserved.