Exemplo n.º 1
0
        public static void Main()
        {
            //init queue
            if (!MessageQueue.Exists(Constants.QUEUE_PATH)) MessageQueue.Create(Constants.QUEUE_PATH, true);

            //init wcf host via code
            Uri baseUri = new Uri("http://localhost:7878/msmqsvc");
            using (ServiceHost host = new ServiceHost(typeof(OrderProcessorService),baseUri))
            {
                //add metadata behavior
                ServiceMetadataBehavior smb = new ServiceMetadataBehavior(){ HttpGetEnabled=true};
                host.Description.Behaviors.Add(smb);

                //add service endpoint
                MsmqIntegrationBinding binding = new MsmqIntegrationBinding(MsmqIntegrationSecurityMode.None);
                host.AddServiceEndpoint(typeof(ClassLib.IOrderProcessor), binding, "msmq.formatname:DIRECT=OS:" + Constants.QUEUE_PATH);

                host.Open();

                // The service can now be accessed.
                Console.WriteLine("The service is ready.");
                Console.WriteLine("Press any key to terminate service.");
                Console.ReadLine();
                host.Close();
            }
        }
Exemplo n.º 2
0
        static void Run()
        {
            MsmqIntegrationBinding binding = new MsmqIntegrationBinding();
            binding.Security.Mode = MsmqIntegrationSecurityMode.None;
            EndpointAddress address = new EndpointAddress("msmq.formatname:DIRECT=OS:" + Constants.QUEUE_PATH);

            ChannelFactory<ClassLib.IOrderProcessor> channelFactory = new ChannelFactory<ClassLib.IOrderProcessor>(binding, address);

            try
            {
                ClassLib.IOrderProcessor channel = channelFactory.CreateChannel();

                MyOrder order = new MyOrder();
                order.ID = DateTime.Now.Ticks.ToString();
                order.Name = "Order_" + order.ID;

                MsmqMessage<MyOrder> ordermsg = new MsmqMessage<MyOrder>(order);
                using (TransactionScope scope = new TransactionScope(TransactionScopeOption.Required))
                {
                    channel.SubmitPurchaseOrderInMessage(ordermsg);
                    scope.Complete();
                }

                Console.WriteLine("Order has been submitted:{0}", ordermsg);
            }
            finally
            {
                channelFactory.Close();
            }
        }
        public static Binding CreateBinding(string bindingName)
        {
            Binding result = null;

            try
            {
                if (string.Compare(bindingName, typeof(WSHttpBinding).FullName, true) == 0)
                {
                    result = new WSHttpBinding();
                }
                else if (string.Compare(bindingName, typeof(WS2007HttpBinding).FullName, true) == 0)
                {
                    result = new WS2007HttpBinding();
                }
                else if (string.Compare(bindingName, typeof(BasicHttpBinding).FullName, true) == 0)
                {
                    result = new BasicHttpBinding();
                }
                else if (string.Compare(bindingName, typeof(WSDualHttpBinding).FullName, true) == 0)
                {
                    result = new WSDualHttpBinding();
                }
                else if (string.Compare(bindingName, typeof(WS2007FederationHttpBinding).FullName, true) == 0)
                {
                    result = new WS2007FederationHttpBinding();
                }
                else if (string.Compare(bindingName, typeof(WSFederationHttpBinding).FullName, true) == 0)
                {
                    result = new WSFederationHttpBinding();
                }
                else if (string.Compare(bindingName, typeof(NetNamedPipeBinding).FullName, true) == 0)
                {
                    result = new NetNamedPipeBinding();
                }
                else if (string.Compare(bindingName, typeof(NetMsmqBinding).FullName, true) == 0)
                {
                    result = new NetMsmqBinding();
                }
                else if (string.Compare(bindingName, typeof(MsmqIntegrationBinding).FullName, true) == 0)
                {
                    result = new MsmqIntegrationBinding();
                }
                else if (string.Compare(bindingName, typeof(NetTcpBinding).FullName, true) == 0)
                {
                    result = new NetTcpBinding();
                }
                else if (string.Compare(bindingName, typeof(NetPeerTcpBinding).FullName, true) == 0)
                {
                    result = new NetPeerTcpBinding();
                }
            }
            catch
            {
                result = new BasicHttpBinding(BasicHttpSecurityMode.None);
            }

            return result;
        }
Exemplo n.º 4
0
        private static void GetMsmqIntegrationBindingDetails(MsmqIntegration.MsmqIntegrationBinding binding, ref string name, ref string mode, ref string credentialType)
        {
            name = GetBindingName <MsmqIntegration.MsmqIntegrationBinding>(binding);

            MsmqIntegration.MsmqIntegrationSecurity msmqIntegrationSecurity = ((MsmqIntegration.MsmqIntegrationBinding)binding).Security;
            mode = msmqIntegrationSecurity?.Mode.ToString();
            switch (msmqIntegrationSecurity?.Mode)
            {
            case MsmqIntegration.MsmqIntegrationSecurityMode.None:
                credentialType = "N/A";
                break;

            case MsmqIntegration.MsmqIntegrationSecurityMode.Transport:
                credentialType = msmqIntegrationSecurity.Transport?.MsmqAuthenticationMode.ToString();
                break;
                // No message mode
            }
        }
 private static Binding FindBinding(BindingType bType)
 {
     switch (bType)
     {
         case BindingType.WebHttp:
             WebHttpBinding webHttpBinding = new WebHttpBinding();
             webHttpBinding.UseDefaultWebProxy = false;
             webHttpBinding.Security.Mode = WebHttpSecurityMode.None;
             webHttpBinding.MaxReceivedMessageSize = MAX_MSG_SIZE;
             webHttpBinding.ReaderQuotas.MaxStringContentLength = MAX_MSG_SIZE;
             webHttpBinding.ReaderQuotas.MaxArrayLength = MAX_MSG_SIZE;
             webHttpBinding.ReaderQuotas.MaxBytesPerRead = MAX_MSG_SIZE;
             webHttpBinding.ReaderQuotas.MaxDepth = MAX_MSG_SIZE;
             webHttpBinding.ReaderQuotas.MaxNameTableCharCount = MAX_MSG_SIZE;
             return webHttpBinding;
         case BindingType.BasicHttp:
             BasicHttpBinding basicHttpBinding = new BasicHttpBinding();
             basicHttpBinding.UseDefaultWebProxy = false;
             basicHttpBinding.Security.Mode = BasicHttpSecurityMode.None;
             basicHttpBinding.MaxReceivedMessageSize = MAX_MSG_SIZE;
             basicHttpBinding.ReaderQuotas.MaxStringContentLength = MAX_MSG_SIZE;
             basicHttpBinding.ReaderQuotas.MaxArrayLength = MAX_MSG_SIZE;
             basicHttpBinding.ReaderQuotas.MaxBytesPerRead = MAX_MSG_SIZE;
             basicHttpBinding.ReaderQuotas.MaxDepth = MAX_MSG_SIZE;
             basicHttpBinding.ReaderQuotas.MaxNameTableCharCount = MAX_MSG_SIZE;
             return basicHttpBinding;
         case BindingType.MsmqIntegration:
             MsmqIntegrationBinding msmqIntegrationBinding = new MsmqIntegrationBinding();
             msmqIntegrationBinding.ExactlyOnce = false;
             msmqIntegrationBinding.UseSourceJournal = true;
             msmqIntegrationBinding.Security.Mode = MsmqIntegrationSecurityMode.None;
             msmqIntegrationBinding.MaxReceivedMessageSize = MAX_MSG_SIZE;
             return msmqIntegrationBinding;
         case BindingType.MsmqIntegrationForPubsub:
             MsmqIntegrationBinding msmqIntegrationForPubsubBinding = new MsmqIntegrationBinding();
             msmqIntegrationForPubsubBinding.ExactlyOnce = false;
             msmqIntegrationForPubsubBinding.UseSourceJournal = true;
             msmqIntegrationForPubsubBinding.Security.Mode = MsmqIntegrationSecurityMode.Transport;
             msmqIntegrationForPubsubBinding.Security.Transport.MsmqAuthenticationMode = MsmqAuthenticationMode.WindowsDomain;
             msmqIntegrationForPubsubBinding.MaxReceivedMessageSize = MAX_MSG_SIZE;
             return msmqIntegrationForPubsubBinding;
         case BindingType.NetMsmq:
             NetMsmqBinding netMsmqBinding = new NetMsmqBinding();
             //netMsmqBinding.ReaderQuotas.MaxStringContentLength = serviceClient.ReaderQuotasMaxStringContentLength;
             netMsmqBinding.ExactlyOnce = false;
             netMsmqBinding.UseSourceJournal = true;
             netMsmqBinding.MaxReceivedMessageSize = MAX_MSG_SIZE;
             netMsmqBinding.ReaderQuotas.MaxStringContentLength = MAX_MSG_SIZE;
             netMsmqBinding.ReaderQuotas.MaxArrayLength = MAX_MSG_SIZE;
             netMsmqBinding.ReaderQuotas.MaxBytesPerRead = MAX_MSG_SIZE;
             netMsmqBinding.ReaderQuotas.MaxDepth = MAX_MSG_SIZE;
             netMsmqBinding.ReaderQuotas.MaxNameTableCharCount = MAX_MSG_SIZE;
             //if (credentialType.HasValue)
             //{
             //    netMsmqBinding.Security.Mode = NetMsmqSecurityMode.Message;
             //    netMsmqBinding.Security.Message.ClientCredentialType = GetMessageCredentialType(credentialType.Value);
             //    netMsmqBinding.Security.Message.AlgorithmSuite = SecurityAlgorithmSuite.Default;
             //}
             return netMsmqBinding;
         case BindingType.NetTcp:
             NetTcpBinding netTcpBinding = new NetTcpBinding();
             //netTcpBinding.ReaderQuotas.MaxStringContentLength = serviceClient.ReaderQuotasMaxStringContentLength;
             //netTcpBinding.ReliableSession.Enabled = serviceClient.ReliableSessionEnabled;
             //netTcpBinding.ReliableSession.Ordered = serviceClient.ReliableSessionOrdered;
             netTcpBinding.MaxReceivedMessageSize = MAX_MSG_SIZE;
             netTcpBinding.ReaderQuotas.MaxStringContentLength = MAX_MSG_SIZE;
             netTcpBinding.ReaderQuotas.MaxArrayLength = MAX_MSG_SIZE;
             netTcpBinding.ReaderQuotas.MaxBytesPerRead = MAX_MSG_SIZE;
             netTcpBinding.ReaderQuotas.MaxDepth = MAX_MSG_SIZE;
             netTcpBinding.ReaderQuotas.MaxNameTableCharCount = MAX_MSG_SIZE;
             //if (credentialType.HasValue)
             //{
             //    netTcpBinding.Security.Mode = SecurityMode.Message;
             //    netTcpBinding.Security.Message.ClientCredentialType = GetMessageCredentialType(credentialType.Value);
             //    netTcpBinding.Security.Message.AlgorithmSuite = SecurityAlgorithmSuite.Default;
             //}
             return netTcpBinding;
         case BindingType.NetNamedPipe:
             NetNamedPipeBinding netNamedPipeBinding = new NetNamedPipeBinding();
             netNamedPipeBinding.Security.Mode = NetNamedPipeSecurityMode.None;
             netNamedPipeBinding.TransactionFlow = false;
             //netNamedPipeBinding.MaxConnections = 100;
             netNamedPipeBinding.MaxReceivedMessageSize = MAX_MSG_SIZE;
             netNamedPipeBinding.ReaderQuotas.MaxStringContentLength = MAX_MSG_SIZE;
             netNamedPipeBinding.ReaderQuotas.MaxArrayLength = MAX_MSG_SIZE;
             netNamedPipeBinding.ReaderQuotas.MaxBytesPerRead = MAX_MSG_SIZE;
             netNamedPipeBinding.ReaderQuotas.MaxDepth = MAX_MSG_SIZE;
             netNamedPipeBinding.ReaderQuotas.MaxNameTableCharCount = MAX_MSG_SIZE;
             return netNamedPipeBinding;
         case BindingType.WSDualHttp:
             WSDualHttpBinding wsDualHttpBinding = new WSDualHttpBinding();
             //wsDualHttpBinding.ReaderQuotas.MaxStringContentLength = serviceClient.ReaderQuotasMaxStringContentLength;
             wsDualHttpBinding.UseDefaultWebProxy = false;
             //wsDualHttpBinding.ReliableSession.Ordered = serviceClient.ReliableSessionOrdered;
             wsDualHttpBinding.MaxReceivedMessageSize = MAX_MSG_SIZE;
             wsDualHttpBinding.ReaderQuotas.MaxStringContentLength = MAX_MSG_SIZE;
             wsDualHttpBinding.ReaderQuotas.MaxArrayLength = MAX_MSG_SIZE;
             wsDualHttpBinding.ReaderQuotas.MaxBytesPerRead = MAX_MSG_SIZE;
             wsDualHttpBinding.ReaderQuotas.MaxDepth = MAX_MSG_SIZE;
             wsDualHttpBinding.ReaderQuotas.MaxNameTableCharCount = MAX_MSG_SIZE;
             //if (credentialType.HasValue)
             //{
             //    wsDualHttpBinding.Security.Mode = WSDualHttpSecurityMode.Message;
             //    wsDualHttpBinding.Security.Message.ClientCredentialType = GetMessageCredentialType(credentialType.Value);
             //    wsDualHttpBinding.Security.Message.NegotiateServiceCredential = true;
             //    wsDualHttpBinding.Security.Message.AlgorithmSuite = SecurityAlgorithmSuite.Default;
             //}
             return wsDualHttpBinding;
         default:
             WSHttpBinding wsHttpBinding = new WSHttpBinding();
             wsHttpBinding.UseDefaultWebProxy = false;
             //wsHttpBinding.ReliableSession.Enabled = serviceClient.ReliableSessionEnabled;
             //wsHttpBinding.ReliableSession.Ordered = serviceClient.ReliableSessionOrdered;
             wsHttpBinding.MaxReceivedMessageSize = MAX_MSG_SIZE;
             wsHttpBinding.ReaderQuotas.MaxStringContentLength = MAX_MSG_SIZE;
             wsHttpBinding.ReaderQuotas.MaxArrayLength = MAX_MSG_SIZE;
             wsHttpBinding.ReaderQuotas.MaxBytesPerRead = MAX_MSG_SIZE;
             wsHttpBinding.ReaderQuotas.MaxDepth = MAX_MSG_SIZE;
             wsHttpBinding.ReaderQuotas.MaxNameTableCharCount = MAX_MSG_SIZE;
             wsHttpBinding.ReceiveTimeout = new TimeSpan(23, 59, 59);
             //if (credentialType.HasValue)
             //{
             //    wsHttpBinding.Security.Mode = SecurityMode.Message;
             //    wsHttpBinding.Security.Message.ClientCredentialType = GetMessageCredentialType(credentialType.Value);
             //    wsHttpBinding.Security.Message.NegotiateServiceCredential = true;
             //    wsHttpBinding.Security.Message.AlgorithmSuite = SecurityAlgorithmSuite.Default;
             //    wsHttpBinding.Security.Message.EstablishSecurityContext = true;
             //}
             return wsHttpBinding;
     }
 }