Click here to Skip to main content
15,881,882 members
Home / Discussions / C#
   

C#

 
AnswerRe: Image compression Pin
User 665825-Oct-08 22:21
User 665825-Oct-08 22:21 
GeneralRe: Image compression Pin
ALAQUNAIBI26-Oct-08 0:36
ALAQUNAIBI26-Oct-08 0:36 
GeneralRe: Image compression Pin
Guffa26-Oct-08 1:42
Guffa26-Oct-08 1:42 
GeneralRe: Image compression Pin
Matty2226-Oct-08 3:12
Matty2226-Oct-08 3:12 
GeneralRe: Image compression Pin
Guffa26-Oct-08 11:03
Guffa26-Oct-08 11:03 
QuestionHow to work with Windows message queue in C#.Net 2005? Pin
Mehral25-Oct-08 15:58
Mehral25-Oct-08 15:58 
AnswerRe: How to work with Windows message queue in C#.Net 2005? Pin
Furty25-Oct-08 16:16
Furty25-Oct-08 16:16 
QuestionWhy *does* this work, and when will it *not* work? (Two-way MSMQ messaging using WCF) Pin
Furty25-Oct-08 15:39
Furty25-Oct-08 15:39 
I've been experimenting with various implementations of two-way communications using WCF over MSMQ, and without ever thinking it would work, tried the following:

using System;
using System.ServiceModel;

namespace MessagingSample
{
    [ServiceContract]
    public interface ISampleContract
    {
        [OperationContract(IsOneWay = true)]
        void StartDoingSomething(string someText, SampleClient client);
    }

    [ServiceBehavior]
    public class SampleClient
    {
        private ISampleContract workerService;

        public void StartClient(string server)
        {
            // Init the service instance
            EndpointAddress endpointAddress = new EndpointAddress(
                new Uri(string.Format(@"net.msmq://{0}/private/SampleQueue", server)));

            NetMsmqBinding clientBinding = new NetMsmqBinding();
            clientBinding.Security.Transport.MsmqAuthenticationMode = MsmqAuthenticationMode.None;
            clientBinding.Security.Transport.MsmqProtectionLevel = System.Net.Security.ProtectionLevel.None;

            ChannelFactory<ISampleContract> channelFactory =
                new ChannelFactory<ISampleContract>(clientBinding, endpointAddress);
            workerService = channelFactory.CreateChannel();

        }

        public void StopClient()
        {
            if (workerService != null)
            {
                workerService = null;
            }
        }

        public void StartDoingSomething(string text)
        {
            if (workerService != null)
            {
                workerService.StartDoingSomething(text, this);
            }
        }

        public void DoSomethingElse(string text)
        {
            System.Diagnostics.Debug.WriteLine(text);
        }
    }


    [ServiceBehavior]
    public class SampleServer : ISampleContract
    {
        private ServiceHost serviceHost = null;

        public void StartServer(string server)
        {
            Uri serviceUri = new Uri(string.Format(@"net.msmq://{0}/private/SampleQueue", server));

            NetMsmqBinding serviceBinding = new NetMsmqBinding();
            serviceBinding.Security.Transport.MsmqAuthenticationMode = MsmqAuthenticationMode.None;
            serviceBinding.Security.Transport.MsmqProtectionLevel = System.Net.Security.ProtectionLevel.None;
            serviceBinding.MaxReceivedMessageSize = 1024 * 4096;
            serviceBinding.ReaderQuotas.MaxArrayLength = 1024 * 4096;

            serviceHost = new ServiceHost(typeof(SampleServer));
            serviceHost.AddServiceEndpoint(typeof(ISampleContract), serviceBinding, serviceUri);

            serviceHost.Open();
        }

        public void StopServer()
        {
            if (serviceHost != null)
            {
                serviceHost.Close();
            }
        }

        // ISampleContract Member
        public void StartDoingSomething(string someText, SampleClient client)
        {
            System.Diagnostics.Debug.WriteLine(someText);
            client.DoSomethingElse("Processed: "+ someText);
        }
    }
}


If you create another couple of applications - one that implements the SampleClient, and another that implements the SampleServer - both will communicate in a two-way fashion over MSMQ using this code.

If the server is down/stopped, messages will be queued and returned to the original client when the server comes back online. In situations where a message is received by the server but the client no longer exists it all fails silently - i.e. no exceptions at the server, and the response method call is simply lost in the ether.

The first question is why does it work? I'm not passing any service endpoints for the client to the server, so how is the server able to address the client? All of the two-way MSMQ/WCF samples I've seen thus far require that the client also act as a server.

The second question is when will it not work?

Note: you'll need to create a queue named "SampleQueue" in MSMQ for this all to work of course.
AnswerRe: Why *does* this work, and when will it *not* work? (Two-way MSMQ messaging using WCF) Pin
Meer Osman Ali25-Oct-08 19:51
Meer Osman Ali25-Oct-08 19:51 
GeneralRe: Why *does* this work, and when will it *not* work? (Two-way MSMQ messaging using WCF) PinPopular
Furty25-Oct-08 20:38
Furty25-Oct-08 20:38 
GeneralRe: Why *does* this work, and when will it *not* work? (Two-way MSMQ messaging using WCF) Pin
Meer Osman Ali25-Oct-08 21:26
Meer Osman Ali25-Oct-08 21:26 
GeneralRe: Why *does* this work, and when will it *not* work? (Two-way MSMQ messaging using WCF) Pin
Furty25-Oct-08 21:32
Furty25-Oct-08 21:32 
GeneralRe: Why *does* this work, and when will it *not* work? (Two-way MSMQ messaging using WCF) Pin
Meer Osman Ali25-Oct-08 21:50
Meer Osman Ali25-Oct-08 21:50 
GeneralRe: Why *does* this work, and when will it *not* work? (Two-way MSMQ messaging using WCF) Pin
Pete O'Hanlon26-Oct-08 10:04
mvePete O'Hanlon26-Oct-08 10:04 
GeneralRe: Why *does* this work, and when will it *not* work? (Two-way MSMQ messaging using WCF) Pin
Luc Pattyn26-Oct-08 10:42
sitebuilderLuc Pattyn26-Oct-08 10:42 
GeneralRe: Why *does* this work, and when will it *not* work? (Two-way MSMQ messaging using WCF) Pin
Pete O'Hanlon26-Oct-08 10:47
mvePete O'Hanlon26-Oct-08 10:47 
GeneralRe: Why *does* this work, and when will it *not* work? (Two-way MSMQ messaging using WCF) Pin
Dave Kreskowiak26-Oct-08 3:44
mveDave Kreskowiak26-Oct-08 3:44 
GeneralRe: Why *does* this work, and when will it *not* work? (Two-way MSMQ messaging using WCF) PinPopular
Eddy Vluggen26-Oct-08 0:31
professionalEddy Vluggen26-Oct-08 0:31 
Questionload xsd into dataset Pin
cheq32625-Oct-08 10:14
cheq32625-Oct-08 10:14 
AnswerRe: load xsd into dataset Pin
Mircea Puiu26-Oct-08 8:21
Mircea Puiu26-Oct-08 8:21 
Questionhow transmit array elements to a table of database at once Pin
mahraja25-Oct-08 8:30
mahraja25-Oct-08 8:30 
AnswerRe: how transmit array elements to a table of database at once Pin
Eddy Vluggen25-Oct-08 8:38
professionalEddy Vluggen25-Oct-08 8:38 
AnswerRe: how transmit array elements to a table of database at once Pin
Wendelius25-Oct-08 8:57
mentorWendelius25-Oct-08 8:57 
QuestionRe: how transmit array elements to a table of database at once Pin
mahraja25-Oct-08 9:13
mahraja25-Oct-08 9:13 
AnswerRe: how transmit array elements to a table of database at once Pin
Wendelius25-Oct-08 9:29
mentorWendelius25-Oct-08 9:29 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.