Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7995177
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T14:19:56+00:00 2026-06-04T14:19:56+00:00

At the moment I have an C# console application that exposes Web Services through

  • 0

At the moment I have an C# console application that exposes Web Services through WebServiceHost those web services are being used by an website but now I’m trying to add SSE to the site.

The code at the client is:

var source = new EventSource(server+'eventSource');
source.onmessage = function (event) {
  alert(event.data);
};  

But on the server side, when I try to define the contract:

[OperationContract]
[WebGet]
String EventSource();

What the service is returning service is a xml with a String.

What should I do on the server side to create a document available for SSE?

Thanks in advace

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T14:19:58+00:00Added an answer on June 4, 2026 at 2:19 pm

    If you have an OperationContract, the return Type is always serialized as XML or optionaly as JSON. If you do not want the return value to be serialized define it as Stream.

    [OperationContract] 
    [WebGet] 
    Stream EventSource(); 
    
    // Implementation Example for returning an unserialized string.
    Stream EventSource()
    {
       // These 4 lines are optional but can spare you a lot of trouble ;)
       OutgoingWebResponseContext context = WebOperationContext.Current.OutgoingResponse;
       context.Headers.Clear();
       context.Headers.Add("cache-control", "no-cache");
       context.ContentType = "text/event-stream"; // change to whatever content type you want to serve.
    
       return new System.IO.MemoryStream(Encoding.ASCII.GetBytes("Some String you want to return without the WCF serializer interfering.")); 
    }
    

    If you build the stream yourself remember to exectute .Seek(0, SeekOrigin.Begin); before you return it.

    EDIT:
    Changed the command order to set the ContentType AFTER the Header gets cleard. Otherwise you would clear the freshly set ContentType too 😉

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In my console application I have a local variable that's working fine the moment
We have a large console application in Haskell that I have been charged with
At the moment I have a DocumentViewer in a WPF window that displays an
At the moment I have a combobox that is populated from the name fields
I have two questions. 1: At the moment I have two model classes that
I have a small business that sells website solutions to clients. The websites serve
I have a console Java application, which runs all the time on a remote
I'm not familiar with delegates and lambdas but at this moment, I have to
hi everybody I would like to write a console application that posts message in
I have just taken over maintenance of a large web application which is over

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.