Return html format to wcf service instead of json or xml

I have an operation contract:

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

and I implemented it as:

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

when I go to this link, I get: enter image description here

how can i format the response as html? or even plain text. I do not want to return html or json ...

I know that I can create a website that requests a service, but I just want to create a simple Console application that works in any browser ...

+8
c # wcf
source share
1 answer

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); } 
+29
source share

All Articles