Click here to Skip to main content
15,894,180 members
Articles / WCF

A Beginner's Guide to Duplex WCF

Rate me:
Please Sign up or sign in to vote.
4.74/5 (31 votes)
8 May 2013CPOL21 min read 194.7K   8.8K   107  
The purpose of this article is to create a service which accepts messages from any client and redistributes those messages to all subscribed clients, and a client that can subscribe to the service, send messages to it and receive unrelated messages from it regardless of how many it sends.
//------------------------------------------------------------------------------
// <auto-generated>
//     This code was generated by a tool.
//     Runtime Version:2.0.50727.4971
//
//     Changes to this file may cause incorrect behavior and will be lost if
//     the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------

namespace GPH_QuickMessageServiceClient.ServiceReference1 {
    
    
    [System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "3.0.0.0")]
    [System.ServiceModel.ServiceContractAttribute(Namespace="GPH_QuickMessageServiceLib", ConfigurationName="ServiceReference1.GPH_QuickMessageService", CallbackContract=typeof(ServiceReference1.GPH_QuickMessageServiceCallback), SessionMode=System.ServiceModel.SessionMode.Required)]
    public interface GPH_QuickMessageService {
        
        [System.ServiceModel.OperationContractAttribute(Action="GPH_QuickMessageServiceLib/GPH_QuickMessageService/JoinTheConversation", ReplyAction="GPH_QuickMessageServiceLib/GPH_QuickMessageService/JoinTheConversationResponse")]
        int JoinTheConversation(string userName);
        
        [System.ServiceModel.OperationContractAttribute(IsOneWay=true, Action="GPH_QuickMessageServiceLib/GPH_QuickMessageService/ReceiveMessage")]
        void ReceiveMessage(string userName, string[] addressList, string userMessage);
        
        [System.ServiceModel.OperationContractAttribute(Action="GPH_QuickMessageServiceLib/GPH_QuickMessageService/LeaveTheConversation", ReplyAction="GPH_QuickMessageServiceLib/GPH_QuickMessageService/LeaveTheConversationResponse")]
        int LeaveTheConversation(string userName);
    }
    
    [System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "3.0.0.0")]
    public interface GPH_QuickMessageServiceCallback {
        
        [System.ServiceModel.OperationContractAttribute(IsOneWay=true, Action="GPH_QuickMessageServiceLib/GPH_QuickMessageService/NotifyUserJoinedTheConversatio" +
            "n")]
        void NotifyUserJoinedTheConversation(string userName);
        
        [System.ServiceModel.OperationContractAttribute(IsOneWay=true, Action="GPH_QuickMessageServiceLib/GPH_QuickMessageService/NotifyUserOfMessage")]
        void NotifyUserOfMessage(string userName, string userMessage);
        
        [System.ServiceModel.OperationContractAttribute(IsOneWay=true, Action="GPH_QuickMessageServiceLib/GPH_QuickMessageService/NotifyUserLeftTheConversation")]
        void NotifyUserLeftTheConversation(string userName);
    }
    
    [System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "3.0.0.0")]
    public interface GPH_QuickMessageServiceChannel : ServiceReference1.GPH_QuickMessageService, System.ServiceModel.IClientChannel {
    }
    
    [System.Diagnostics.DebuggerStepThroughAttribute()]
    [System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "3.0.0.0")]
    public partial class GPH_QuickMessageServiceClient : System.ServiceModel.DuplexClientBase<ServiceReference1.GPH_QuickMessageService>, ServiceReference1.GPH_QuickMessageService {
        
        public GPH_QuickMessageServiceClient(System.ServiceModel.InstanceContext callbackInstance) : 
                base(callbackInstance) {
        }
        
        public GPH_QuickMessageServiceClient(System.ServiceModel.InstanceContext callbackInstance, string endpointConfigurationName) : 
                base(callbackInstance, endpointConfigurationName) {
        }
        
        public GPH_QuickMessageServiceClient(System.ServiceModel.InstanceContext callbackInstance, string endpointConfigurationName, string remoteAddress) : 
                base(callbackInstance, endpointConfigurationName, remoteAddress) {
        }
        
        public GPH_QuickMessageServiceClient(System.ServiceModel.InstanceContext callbackInstance, string endpointConfigurationName, System.ServiceModel.EndpointAddress remoteAddress) : 
                base(callbackInstance, endpointConfigurationName, remoteAddress) {
        }
        
        public GPH_QuickMessageServiceClient(System.ServiceModel.InstanceContext callbackInstance, System.ServiceModel.Channels.Binding binding, System.ServiceModel.EndpointAddress remoteAddress) : 
                base(callbackInstance, binding, remoteAddress) {
        }
        
        public int JoinTheConversation(string userName) {
            return base.Channel.JoinTheConversation(userName);
        }
        
        public void ReceiveMessage(string userName, string[] addressList, string userMessage) {
            base.Channel.ReceiveMessage(userName, addressList, userMessage);
        }
        
        public int LeaveTheConversation(string userName) {
            return base.Channel.LeaveTheConversation(userName);
        }
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer
Ireland Ireland
My first program was written in Basic on a Sinclair Spectrum ZX 16K in the summer of '85. Having studied Computer Systems I attempted to break into the world of C but took a wrong turn and got immersed in COBOL!

I looked a C again in 1994 but didnt follow up on it. In 2001 I introduced myself to Visual C++ 6.0 courtesy of Ivor Hortons book, but found the going difficult. I tipped my toe in the .NET water in '05 but the first example I tried in VC++ 2005 express didnt work and allied with the absence of MFC in the express package, I parked that up.

Along the way my career got shunted into software testing

A personal machine change force me to migrate to VS2008 in 2008. The new edition of Ivor Hortons book for VC++ in VS2008 reintroduced me to .NET and I got curious whereupon I went out and acquired Stephen Fraser's "Pro Visual C++/CLI and
the .NET 3.5 Platform". I was hooked!

After 20 years I think I finally found my destination.

But it would take a further 8 years of exile before I was reappointed to a developer role. In that time I migrated to C# and used selenium wedriver (courtesy of Arun Motoori's Selenium By Arun) as the catalyst to finally grab the opportunity.

Comments and Discussions