I have written a WCF service which is designed to replace some defunct cgi-bin code. The original HTML which calls the cgi (which returns the Url of a new site to visit) was like this
href="http://example.com/cgi-bin/webring/list.cgi?ringid=xxx;siteid=47"
The new HTML that I am trying is this:
href="http://example.com/webring.svc/RJump/47,xxx"
The resulting HTML will be distributed, to be added to several existing websites.
I have set up the WCF service to return a plain text string containing the required Url, but when the relevant button is pressed (on the originating site), the browser just opens an (almost) blank page containing just the Url as a string, rather than opening the page it refers to.
I'm not sure if it's just my HTML being incorrect, or if the service is returning the wrong type. Here is the interface:
[ServiceContract]
public interface IWebRing
{
// bare response for calling from HTML
[OperationContract]
[WebGet(UriTemplate = "/RJump/{data}", BodyStyle = WebMessageBodyStyle.Bare)]
System.IO.Stream RJump(string data);
}
and this is the (simplified) method (I 'borrowed' the code from here):
public System.IO.Stream RJump(string data)
{
string Url = "http://example.net";
// 'data' will define which site is actually required
System.ServiceModel.Web.OutgoingWebResponseContext context = System.ServiceModel.Web.WebOperationContext.Current.OutgoingResponse;
context.Headers.Add(System.Net.HttpResponseHeader.CacheControl, "public");
context.ContentType = "text/plain";
context.LastModified = DateTime.Now;
context.StatusCode = System.Net.HttpStatusCode.OK;
System.IO.Stream result = new System.IO.MemoryStream(System.Text.ASCIIEncoding.Default.GetBytes(Url));
return result;
}
I had already got everything working using javascript and an async fetch()
, but some users don't want to add script to their sites so this alternative solution must be pure HTML (as was the original).