Click here to Skip to main content
15,887,676 members
Articles / High Performance Computing / Parallel Processing

Distributed and Parallel Processing using WCF

Rate me:
Please Sign up or sign in to vote.
4.24/5 (9 votes)
19 Apr 2009CPOL7 min read 108.2K   1.9K   41  
How to provide parallel and distributed computing capabilities using WCF
//------------------------------------------------------------------------------
// <auto-generated>
//     This code was generated by a tool.
//     Runtime Version:2.0.50727.3053
//
//     Changes to this file may cause incorrect behavior and will be lost if
//     the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------

namespace Master.ServiceReference {
    
    
    [System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "3.0.0.0")]
    [System.ServiceModel.ServiceContractAttribute(ConfigurationName="ServiceReference.IJobPerformer")]
    public interface IJobPerformer {
        
        [System.ServiceModel.OperationContractAttribute(Action="http://tempuri.org/IJobPerformer/SaveEntries", ReplyAction="http://tempuri.org/IJobPerformer/SaveEntriesResponse")]
        bool SaveEntries(int fileId, string message, int count);
        
        [System.ServiceModel.OperationContractAttribute(AsyncPattern=true, Action="http://tempuri.org/IJobPerformer/SaveEntries", ReplyAction="http://tempuri.org/IJobPerformer/SaveEntriesResponse")]
        System.IAsyncResult BeginSaveEntries(int fileId, string message, int count, System.AsyncCallback callback, object asyncState);
        
        bool EndSaveEntries(System.IAsyncResult result);
    }
    
    [System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "3.0.0.0")]
    public interface IJobPerformerChannel : IJobPerformer, System.ServiceModel.IClientChannel {
    }
    
    [System.Diagnostics.DebuggerStepThroughAttribute()]
    [System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "3.0.0.0")]
    public partial class SaveEntriesCompletedEventArgs : System.ComponentModel.AsyncCompletedEventArgs {
        
        private object[] results;
        
        public SaveEntriesCompletedEventArgs(object[] results, System.Exception exception, bool cancelled, object userState) : 
                base(exception, cancelled, userState) {
            this.results = results;
        }
        
        public bool Result {
            get {
                base.RaiseExceptionIfNecessary();
                return ((bool)(this.results[0]));
            }
        }
    }
    
    [System.Diagnostics.DebuggerStepThroughAttribute()]
    [System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "3.0.0.0")]
    public partial class JobPerformerClient : System.ServiceModel.ClientBase<IJobPerformer>, ServiceReference.IJobPerformer {
        
        private BeginOperationDelegate onBeginSaveEntriesDelegate;
        
        private EndOperationDelegate onEndSaveEntriesDelegate;
        
        private System.Threading.SendOrPostCallback onSaveEntriesCompletedDelegate;
        
        public JobPerformerClient() {
        }
        
        public JobPerformerClient(string endpointConfigurationName) : 
                base(endpointConfigurationName) {
        }
        
        public JobPerformerClient(string endpointConfigurationName, string remoteAddress) : 
                base(endpointConfigurationName, remoteAddress) {
        }
        
        public JobPerformerClient(string endpointConfigurationName, System.ServiceModel.EndpointAddress remoteAddress) : 
                base(endpointConfigurationName, remoteAddress) {
        }
        
        public JobPerformerClient(System.ServiceModel.Channels.Binding binding, System.ServiceModel.EndpointAddress remoteAddress) : 
                base(binding, remoteAddress) {
        }
        
        public event System.EventHandler<SaveEntriesCompletedEventArgs> SaveEntriesCompleted;
        
        public bool SaveEntries(int fileId, string message, int count) {
            return base.Channel.SaveEntries(fileId, message, count);
        }
        
        [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Advanced)]
        public System.IAsyncResult BeginSaveEntries(int fileId, string message, int count, System.AsyncCallback callback, object asyncState) {
            return base.Channel.BeginSaveEntries(fileId, message, count, callback, asyncState);
        }
        
        [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Advanced)]
        public bool EndSaveEntries(System.IAsyncResult result) {
            return base.Channel.EndSaveEntries(result);
        }
        
        private System.IAsyncResult OnBeginSaveEntries(object[] inValues, System.AsyncCallback callback, object asyncState) {
            int fileId = ((int)(inValues[0]));
            string message = ((string)(inValues[1]));
            int count = ((int)(inValues[2]));
            return this.BeginSaveEntries(fileId, message, count, callback, asyncState);
        }
        
        private object[] OnEndSaveEntries(System.IAsyncResult result) {
            bool retVal = this.EndSaveEntries(result);
            return new object[] {
                    retVal};
        }
        
        private void OnSaveEntriesCompleted(object state) {
            if ((this.SaveEntriesCompleted != null)) {
                InvokeAsyncCompletedEventArgs e = ((InvokeAsyncCompletedEventArgs)(state));
                this.SaveEntriesCompleted(this, new SaveEntriesCompletedEventArgs(e.Results, e.Error, e.Cancelled, e.UserState));
            }
        }
        
        public void SaveEntriesAsync(int fileId, string message, int count) {
            this.SaveEntriesAsync(fileId, message, count, null);
        }
        
        public void SaveEntriesAsync(int fileId, string message, int count, object userState) {
            if ((this.onBeginSaveEntriesDelegate == null)) {
                this.onBeginSaveEntriesDelegate = new BeginOperationDelegate(this.OnBeginSaveEntries);
            }
            if ((this.onEndSaveEntriesDelegate == null)) {
                this.onEndSaveEntriesDelegate = new EndOperationDelegate(this.OnEndSaveEntries);
            }
            if ((this.onSaveEntriesCompletedDelegate == null)) {
                this.onSaveEntriesCompletedDelegate = new System.Threading.SendOrPostCallback(this.OnSaveEntriesCompleted);
            }
            base.InvokeAsync(this.onBeginSaveEntriesDelegate, new object[] {
                        fileId,
                        message,
                        count}, this.onEndSaveEntriesDelegate, this.onSaveEntriesCompletedDelegate, userState);
        }
    }
}

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
Architect Imfinity
India India
Hi I have been working on enterprise applications for last six years.

Comments and Discussions