Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. .NET (Core and Framework)
  4. Getting to know WCF questions.

Getting to know WCF questions.

Scheduled Pinned Locked Moved .NET (Core and Framework)
csharpwcflounge
1 Posts 1 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    Snowjim
    wrote on last edited by
    #1

    Hey! I am building on a simple chat application that uses callbacks. The contract are created in a class library that are then referd to in myWCFCallBackHost, the contract looks like this: Contract: namespace myWCFCallBackService { /// /// The interface the service exposes /// One Session to each client /// [ServiceContract(SessionMode=SessionMode.Required, CallbackContract = typeof(IChangedHandler))] public interface IChat { //Opens a new session when executed [OperationContract(IsOneWay=false, IsInitiating = true)] void Subscribe(string inName); //Close the current session bound to the current client [OperationContract(IsOneWay = false, IsTerminating = true)] void Unsubscribe(); //Lets the client post a message [OperationContract(IsOneWay = true)] void publishNewMessage(string inMessage, string inName); } /// /// The interface that clients must implement /// public interface IChangedHandler { [OperationContract(IsOneWay = true)] void changed(string newMessage); } /// /// A singelton object of the chat class to be able to subscribe clients /// [ServiceBehavior(InstanceContextMode=InstanceContextMode.Single)] public class chat : IChat { private List mSubscribers = new List(); public chat() { } public void Subscribe(string inName) { mSubscribers.Add(OperationContext.Current.GetCallbackChannel()); } public void Unsubscribe() { IChangedHandler caller = OperationContext.Current.GetCallbackChannel(); foreach (IChangedHandler ch in mSubscribers) { if (ch == caller) { mSubscribers.Remove(ch); break; } } } public void publishNewMessage(string inMessage, string inName) { int nIndex = 0; try { foreach (IChangedHandler ch in mSubscribers) { ch.changed(inMessage); nIndex++; } } catch (Exception ex) { mSubscr

    1 Reply Last reply
    0
    Reply
    • Reply as topic
    Log in to reply
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes


    • Login

    • Don't have an account? Register

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • World
    • Users
    • Groups