Example #1
0
		public void CreateBindingElements ()
		{
			BindingElementCollection bl = new NetMsmqBinding ().CreateBindingElements ();
			Assert.AreEqual (2, bl.Count, "#1");
			Assert.IsTrue (bl [0] is BinaryMessageEncodingBindingElement, "#2");
			Assert.IsTrue (bl [1] is MsmqTransportBindingElement, "#3");
		}
Example #2
0
        /// <summary>
        /// one-way call to resample an image volume
        /// </summary>
        /// <param name="seriesInstanceUID"></param>
        public void ResampleImageVolume(ImageVolumeResampleRequest request)
        {
            _responseContext =
                OperationContext.Current.IncomingMessageHeaders.GetHeader<ResponseContext>(
                    "ResponseContext", "ServiceModelEx");
            _responseAddress =
                new EndpointAddress(_responseContext.ResponseAddress);

            ResampleEngineClient re = new ResampleEngineClient();

            ImageVolumeResampleResponse response = re.ResampleImageVolume(request);
            System.Diagnostics.Trace.Assert(response.ResampledImageVolumeGuid.CompareTo(Guid.Empty) != 0);

            MessageHeader<ResponseContext> responseHeader = new MessageHeader<ResponseContext>(_responseContext);
            NetMsmqBinding binding = new NetMsmqBinding("NoMsmqSecurity");
            ResampleResponseProxy proxy = new ResampleResponseProxy(binding, _responseAddress);

            using (OperationContextScope scope = new OperationContextScope(proxy.InnerChannel))
            {
                OperationContext.Current.OutgoingMessageHeaders.Add(
                    responseHeader.GetUntypedHeader("ResponseContext", "ServiceModelEx"));

                proxy.OnResampleDone(response);
            }

            proxy.Close();
        }
        public void Submit(Order order)
        {
            Console.WriteLine("Begin to process the order of the order No.: {0}", order.OrderNo);
            FaultException exception = null;
            if (order.OrderDate < DateTime.Now) {
                exception = new FaultException(new FaultReason("The order has expried"), new FaultCode("sender"));
                Console.WriteLine("It's fail to process the order.\n\tOrder No.: {0}\n\tReason:{1}", order.OrderNo, "The order has expried");
            } else {
                Console.WriteLine("It's successful to process the order.\n\tOrder No.: {0}", order.OrderNo);
            }
            NetMsmqBinding binding = new NetMsmqBinding();
            binding.ExactlyOnce = false;
            binding.Security.Transport.MsmqAuthenticationMode = MsmqAuthenticationMode.None;
            binding.Security.Transport.MsmqProtectionLevel = ProtectionLevel.None;

            ChannelFactory<IOrderRessponse> channelFactory = new ChannelFactory<IOrderRessponse>(binding);
            OrderResponseContext responseContext = OrderResponseContext.Current;

            IOrderRessponse channel = channelFactory.CreateChannel(new EndpointAddress(responseContext.ResponseAddress));

            using (OperationContextScope contextScope = new OperationContextScope(channel as IContextChannel)) {
                channel.SubmitOrderResponse(order.OrderNo, exception);
            }
            Console.Read();
        }
        public static void Run(int numberOfMessage)
        {
            try
            {
                int Iteration = numberOfMessage;

                string address = "net.msmq://localhost/private/ReceiveTx";
                NetMsmqBinding binding = new NetMsmqBinding(NetMsmqSecurityMode.None)
                {
                    ExactlyOnce = true,
                    Durable = true
                };

                ChannelFactory<IPurchaseOrderService> channelFactory = new ChannelFactory<IPurchaseOrderService>(binding, address);
                IPurchaseOrderService channel = channelFactory.CreateChannel();

                for (int i = 0; i < Iteration; i++)
                {
                    PurchaseOrder po = new PurchaseOrder()
                    {
                        PONumber = Guid.NewGuid().ToString(),
                        CustomerId = string.Format("CustomerId: {0}", i)
                    };

                    Console.WriteLine("Submitting an PO ...");
                    channel.SubmitPurchaseOrder(po);
                }

                channelFactory.Close();
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }
        }
        private void HostReviewSubscriberService()
        {
            // create review queue
            EnsureReviewQueueExists();


            ServiceHost lHost = new ServiceHost(typeof(MediaReviewsCompanyAdapter));

            /**
            lHost.AddServiceEndpoint(typeof(IReviewSubscriber), 
                new NetTcpBinding(),
                cSubscriberServiceAddress);
            */


            /**
             * NEWLY ADDED
             * host the service of review queue
             */
            
            NetMsmqBinding lBinding = new NetMsmqBinding();
            lBinding.Security.Mode = NetMsmqSecurityMode.None;
            lHost.AddServiceEndpoint(typeof(IReviewSubscriber),
                lBinding,
                getWCFQueueName());
            

            lHost.Open();
        }
        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;
        }
Example #7
0
        static void Main(string[] args)
        {
            Console.WriteLine("Server is Running...");
            using (var host = new ServiceHost(typeof(Server)))
            {
                var bin = new NetMsmqBinding(NetMsmqSecurityMode.None);
                host.AddServiceEndpoint(typeof(IServer), bin, "net.msmq://localhost/private/requestqueue");
                host.Open();

                Console.ReadLine();
            }
        }
Example #8
0
        static void Main(string[] args)
        {
            using (var host = new ServiceHost(typeof(Client)))
            {
                var bin = new NetMsmqBinding(NetMsmqSecurityMode.None);
                host.AddServiceEndpoint(typeof(IClient), bin, "net.msmq://localhost/private/responsequeue");
                host.Open();

                var proxy = new Serveice();
                proxy.Request(700);
                Console.ReadLine();
            }
        }
Example #9
0
        /**
         * NEWLY ADDED 
         */
        private void HostBankReturnService()
        {
            EnsureResponeQueueExists();
            ServiceHost lHost = new ServiceHost(typeof(BankAdapter));
            NetMsmqBinding lBinding = new NetMsmqBinding();
            lBinding.Security.Mode = NetMsmqSecurityMode.None;

            lHost.AddServiceEndpoint(typeof(IOperationOutcomeService),
                lBinding,
                getWCFQueueName());

            lHost.Open();
        }
        public void GenerateMpr(MprGenerationRequestV1 request)
        {
            var responseContext =
                OperationContext.Current.IncomingMessageHeaders.GetHeader<ResponseContext>(
                    "ResponseContext", "ServiceModelEx");
            System.Diagnostics.Trace.Assert(responseContext.MethodId.CompareTo(Guid.Empty.ToString()) != 0);

            LocalImageResourceManagerClient lirm =
                new LocalImageResourceManagerClient();
            lirm.Open();

            UniformImageVolumeDataContract ivdc = null;
            ivdc = lirm.GetImageVolume(request.ImageVolumeId);

            int[] size = CalculateSize(ivdc, request.Orientation);

            ImageDataContract idc = null;
            _cacheResultImages.TryGetValue(responseContext.MethodId, out idc);
            if (idc == null
                || idc.Width != size[0]
                || idc.Height != size[1])
            {
                idc = new ImageDataContract();
                idc.Width = size[0];
                idc.Height = size[1];
                idc = lirm.AddImage(idc);
                _cacheResultImages.TryAdd(responseContext.MethodId, idc);
            }

            lirm.Close();

            UpdatePixelsFromVolumeResampled(ivdc,
                request.Orientation, request.SlicePosition,
                request.WindowCenter, request.WindowWidth,
                idc);

            MessageHeader<ResponseContext> responseHeader = new MessageHeader<ResponseContext>(responseContext);
            NetMsmqBinding binding = new NetMsmqBinding("NoMsmqSecurity");
            MprGenerationResponseProxy proxy = new MprGenerationResponseProxy(binding,
                new EndpointAddress(responseContext.ResponseAddress));

            using (OperationContextScope scope = new OperationContextScope(proxy.InnerChannel))
            {
                OperationContext.Current.OutgoingMessageHeaders.Add(
                    responseHeader.GetUntypedHeader("ResponseContext", "ServiceModelEx"));

                proxy.OnMprDone(idc, request.RequestTime);
            }

            proxy.Close();
        }
 public static Binding Resolve(WcfBindingTypes type)
 {
     Binding binding = null;
     switch (type)
     {
         case WcfBindingTypes.BasicHttpBinding:
             binding = new BasicHttpBinding();
             break;
         case WcfBindingTypes.NetTcpBinding:
             binding = new NetTcpBinding();
             break;
         case WcfBindingTypes.NetTcpContextBinding:
             binding = new NetTcpContextBinding();
             break;
         case WcfBindingTypes.WsHttpBinding:
             binding = new WSHttpBinding();
             break;
         case WcfBindingTypes.NetMsmqBinding:
             binding = new NetMsmqBinding();
             break;
         case WcfBindingTypes.NetPeerTcpBinding:
             binding = new NetPeerTcpBinding();
             break;
         case WcfBindingTypes.BasicHttpContextBinding:
             binding = new BasicHttpContextBinding();
             break;
         case WcfBindingTypes.WSHttpContextBinding:
             binding = new WSHttpContextBinding();
             break;
         case WcfBindingTypes.WS2007FederationHttpBinding:
             binding = new WS2007FederationHttpBinding();
             break;
         case WcfBindingTypes.WS2007HttpBinding:
             binding = new WS2007HttpBinding();
             break;
         case WcfBindingTypes.NetNamedPipeBinding:
             binding = new NetNamedPipeBinding();
             break;
         case WcfBindingTypes.WSFederationHttpBinding:
             binding = new WSFederationHttpBinding();
             break;
         case WcfBindingTypes.WSDualHttpBinding:
             binding = new WSDualHttpBinding();
             break;
         default:
             binding = new CustomBinding();
             break;
     }
     return binding;
 }
Example #12
0
	public static void Main ()
	{
		ServiceHost host = new ServiceHost (typeof (TestService));

		NetMsmqBinding b = new NetMsmqBinding ();
		b.ExactlyOnce = false; // non-tx
		b.Security.Transport.MsmqAuthenticationMode =
			MsmqAuthenticationMode.None;
		b.Security.Transport.MsmqProtectionLevel = ProtectionLevel.None;

		host.AddServiceEndpoint ("ITestService", b, new Uri ("net.msmq://localhost/private/monowcftest"));

		host.Open ();
		Console.WriteLine ("Hit [CR] key to close ...");
		Console.ReadLine ();
		host.Close ();
	}
        public static void SendNumbers(Uri queueAddress, int numberOfMessages)
        {
            NetMsmqBinding binding = new NetMsmqBinding(NetMsmqSecurityMode.None);
            ChannelFactory<IProductCalculator> factory = 
                    new ChannelFactory<IProductCalculator>(binding);
            factory.Open();
            IProductCalculator ipc = factory.CreateChannel(new EndpointAddress(queueAddress.ToString()));

            Random rand = new Random();
            for (int i = 0; i < numberOfMessages; i++)
            {
                int num1 = rand.Next(1, 10);
                int num2 = rand.Next(1, 10);
                ipc.CalculateProduct(num1, num2);
            }
            factory.Close();
        }
Example #14
0
        static void Main(string[] args)
        {
            CreateMessageQueue(queuePrefix + queueName);

            NetMsmqBinding binding = new NetMsmqBinding(NetMsmqSecurityMode.None);
            Uri address = new Uri(queueLocation + queueName);

            // Specify the behavior of the service host - the ProductCalculator methods.
            ServiceHost serviceHost = new ServiceHost(typeof(ProductCalculator));
            // Specify the Contract, Binding and Address to service.
            serviceHost.AddServiceEndpoint(typeof(IProductCalculator), binding, address);

            try
            {
                // Begin processing messages.
                serviceHost.Open();

            		SendTwoRandomNumbers.SendNumbers(address, 10);

            		// Wait for the service hosts to process the messages.
            		Console.WriteLine("Press enter when messages have been received.");
            		Console.ReadLine();

                // Cease processing messages.
            		serviceHost.Close();

            		DeleteMessageQueue(queuePrefix + queueName);
            }
            catch (AddressAccessDeniedException)
            {
                Console.WriteLine("Ensure this process is running with elevated"
                        + " privileges.");
            }
            catch (TimeoutException)
            {
                Console.WriteLine("ServiceHost timed out during the open or close"
                        + " operation.");
            }
            catch (CommunicationException)
            {
                Console.WriteLine("ServiceHost was unable to open or close properly.");
            }
        }
 public Binding Create(Endpoint serviceInterface)
 {
     var mqbinding = new NetMsmqBinding(NetMsmqSecurityMode.None)
                        {
                            ExactlyOnce = serviceInterface.ExactlyOnce,
                            Durable = serviceInterface.Durable.EqualsCaseInsensitive("true"),
                            ReceiveErrorHandling = ReceiveErrorHandling.Drop,
                            ReceiveRetryCount = 0,
                            MaxRetryCycles = 1,
                            RetryCycleDelay = TimeSpan.FromSeconds(5),
                            MaxBufferPoolSize = int.MaxValue,
                            MaxReceivedMessageSize = int.MaxValue,
                            UseActiveDirectory = false,
                            ReceiveContextEnabled = true,
                            ReaderQuotas = XmlDictionaryReaderQuotas.Max
                        };
     mqbinding.Security.Transport.MsmqAuthenticationMode = MsmqAuthenticationMode.None;
     mqbinding.Security.Transport.MsmqProtectionLevel = ProtectionLevel.None;
     return mqbinding;
 }
Example #16
0
        /// <summary>
        /// begin meshing for a particular structure
        /// </summary>
        /// <param name="request"></param>
        public void MeshStructure(MeshingRequest request)
        {
            // store the return address
            _responseContext =
                OperationContext.Current.IncomingMessageHeaders.GetHeader<ResponseContext>(
                    "ResponseContext", "ServiceModelEx");
            _responseAddress =
                new EndpointAddress(_responseContext.ResponseAddress);

            // notify that we are performing a meshing
            System.Diagnostics.Trace.WriteLine(
                string.Format("Meshing for structure {0} ({1} contours)",
                    request.StructureGuid,
                    request.ContourGuids != null 
                        ? request.ContourGuids.Count.ToString() : "?"));

            // create the engine
            MeshingEngineClient meshingEngine = new MeshingEngineClient();

            // synchronous call to perform meshing
            MeshingResponse response = meshingEngine.MeshStructure(request);
            meshingEngine.Close();

            // now construct the response proxy based on the return address
            MessageHeader<ResponseContext> responseHeader = new MessageHeader<ResponseContext>(_responseContext);
            NetMsmqBinding binding = new NetMsmqBinding("NoMsmqSecurity");
            MeshingResponseProxy proxy = new MeshingResponseProxy(binding, _responseAddress);

            // and set up the operation context to relay response info
            using (OperationContextScope scope = new OperationContextScope(proxy.InnerChannel))
            {
                OperationContext.Current.OutgoingMessageHeaders.Add(
                    responseHeader.GetUntypedHeader("ResponseContext", "ServiceModelEx"));

                // send the response
                proxy.OnMeshingDone(response);
            }

            proxy.Close();
        }
        /// <summary>
        /// Create reporter connected via given client certificate.
        /// </summary>
        /// <param name="address">Valid target address of service.</param>
        /// <param name="cert">Valid certificate.</param>
        private IndicationReporterProxy(Uri address, X509Certificate2 cert)
        {
            if (address == null)
            {
                throw new ArgumentNullException("address");
            }

            if (cert == null)
            {
                throw new ArgumentNullException("cert");
            }

            var binding = new NetMsmqBinding(NetMsmqSecurityMode.Message);
            binding.Security.Mode = NetMsmqSecurityMode.Message;
            binding.Security.Message.ClientCredentialType = MessageCredentialType.Certificate;                                                                    

            var end = new EndpointAddress(address, EndpointIdentity.CreateX509CertificateIdentity(cert));            
            channelFactory = new ChannelFactory<IIndicationReporter>(binding, end);
            channelFactory.Credentials.ServiceCertificate.Authentication.CertificateValidationMode = X509CertificateValidationMode.None;
            channelFactory.Credentials.ClientCertificate.Certificate = cert;

            log.DebugFormat("ChannelFactory created - {0}", address.ToString());        
        }
Example #18
0
		public void DefaultValues ()
		{
			NetMsmqBinding b = new NetMsmqBinding ();
			Assert.AreEqual (EnvelopeVersion.Soap12, b.EnvelopeVersion, "#1");
			Assert.AreEqual (0x80000, b.MaxBufferPoolSize, "#2");
			Assert.AreEqual (QueueTransferProtocol.Native, b.QueueTransferProtocol, "#2");
			Assert.IsNotNull (b.ReaderQuotas, "#3");
			Assert.IsFalse (b.UseActiveDirectory, "#4");

			Assert.IsNull (b.CustomDeadLetterQueue, "#5");
			Assert.AreEqual (DeadLetterQueue.System, b.DeadLetterQueue, "#6");
			Assert.IsTrue (b.Durable, "#7");
			Assert.IsTrue (b.ExactlyOnce, "#8");
			Assert.AreEqual (0x10000, b.MaxReceivedMessageSize, "#9");
			Assert.AreEqual (2, b.MaxRetryCycles, "#10");
			Assert.AreEqual (ReceiveErrorHandling.Fault, b.ReceiveErrorHandling, "#11");
			Assert.AreEqual (5, b.ReceiveRetryCount, "#12");
			// hmm, it is documented as 10 minutes but ...
			Assert.AreEqual (TimeSpan.FromMinutes (30), b.RetryCycleDelay, "#13");
			Assert.AreEqual ("net.msmq", b.Scheme, "#14");
			Assert.AreEqual (TimeSpan.FromDays (1), b.TimeToLive, "#15");
			Assert.IsFalse (b.UseMsmqTracing, "#16");
			Assert.IsFalse (b.UseSourceJournal, "#17");
		}
Example #19
0
 public static Binding GetMsmqBinding(bool transactional, NetMsmqSecurityMode mode)
 {
     var binding = new NetMsmqBinding(mode);
     Configure(binding, transactional);
     return binding;
 }
Example #20
0
        private static void Configure(NetMsmqBinding binding, bool trasactional)
        {
            if (binding == null)
                throw new ArgumentNullException("binding");

            binding.SendTimeout = new TimeSpan(0, 0, 10, 0);
            binding.OpenTimeout = new TimeSpan(0, 0, 10, 0);
            binding.CloseTimeout = new TimeSpan(0, 0, 10, 0);
            binding.ReceiveTimeout = new TimeSpan(0, 0, 10, 0);
            binding.DeadLetterQueue = DeadLetterQueue.System;
            binding.Durable = true;
            binding.ExactlyOnce = trasactional;
            binding.UseActiveDirectory = false;

            binding.MaxBufferPoolSize = 2147483647;
            binding.MaxReceivedMessageSize = Int32.MaxValue;
            binding.MaxRetryCycles = 2;
            binding.ReceiveErrorHandling = ReceiveErrorHandling.Fault;
            binding.ReceiveRetryCount = 5;
            binding.RetryCycleDelay = new TimeSpan(0, 0, 30, 0);
            binding.TimeToLive = new TimeSpan(1, 0, 0, 0);

            binding.UseSourceJournal = false;
            binding.UseMsmqTracing = false;
            binding.QueueTransferProtocol = QueueTransferProtocol.Native;

            binding.ReaderQuotas.MaxArrayLength = Int32.MaxValue;
            binding.ReaderQuotas.MaxBytesPerRead = Int32.MaxValue;
            binding.ReaderQuotas.MaxDepth = Int32.MaxValue;
            binding.ReaderQuotas.MaxNameTableCharCount = Int32.MaxValue;
            binding.ReaderQuotas.MaxStringContentLength = Int32.MaxValue;
        }
Example #21
0
 public static Binding GetMsmqBinding(bool transactional)
 {
     var binding = new NetMsmqBinding();
     Configure(binding, transactional);
     return binding;
 }
Example #22
0
        static void Main(string[] args)
        {
            if (!MessageQueue.Exists(@".\private$\filaWCF"))
                MessageQueue.Create(@".\private$\filaWCF", true);  //ATENÇÃO: por omissão, a fila tem de ser transaccional

            NetMsmqBinding b = new NetMsmqBinding();
            b.ReceiveErrorHandling = ReceiveErrorHandling.Drop;

            ServiceHost host =
                    new ServiceHost(typeof(Servico));

            host.Open();
            Console.WriteLine("Serviço iniciado. Enter para terminar");
            Console.ReadLine();
            host.Close();
            MessageQueue.Delete(@".\private$\filaWCF");//grupo5

        }
        private NetMsmqBinding CreateBinding(Type messageType)
        {
            var binding = new NetMsmqBinding(NetMsmqSecurityMode.None);
            binding.TimeToLive = messageType.TimeToLive();

            if (messageType.IsTransactional())
            {
                if (this.useCustomDeadLetterQueue)
                {
                    binding.DeadLetterQueue = DeadLetterQueue.Custom;
                    binding.CustomDeadLetterQueue = this.CurrentAppEndpoints[BusEndpointType.TxDeadLetter].Uri;
                }
            }
            else
            {
                binding.ExactlyOnce = false;
                binding.Durable = false;
                binding.DeadLetterQueue = DeadLetterQueue.None;
            }

            return binding;
        }
Example #24
0
 public static Binding GetMsmqBinding(String bindingName)
 {
     var binding = new NetMsmqBinding(bindingName);
     return binding;
 }
Example #25
0
File: Service.cs Project: rmc00/gsf
        /// <summary>
        /// Creates a <see cref="Binding"/> based on the specified <paramref name="address"/>.
        /// </summary>
        /// <param name="address">The URI that is used to determine the type of <see cref="Binding"/> to be created.</param>
        /// <param name="enableSecurity">A boolean value that indicated whether security is to be enabled on the <see cref="Binding"/>.</param>
        /// <returns>An <see cref="Binding"/> object if a valid <paramref name="address"/> is specified; otherwise null.</returns>
        /// <remarks>
        /// This list shows all valid address schemes that can be specified in the <paramref name="address"/>:
        /// <list type="table">
        ///     <listheader>
        ///         <term>Address Scheme</term>
        ///         <description>Usage</description>
        ///     </listheader>
        ///     <item>
        ///         <term><b>http://</b> or <b>http.soap11://</b></term>
        ///         <description>An <paramref name="address"/> of <b>http.soap11://localhost:2929</b> will create an <see cref="BasicHttpBinding"/> and update the <paramref name="address"/> to <b>http://localhost:2929</b>.</description>
        ///     </item>
        ///     <item>
        ///         <term><b>http.soap12://</b></term>
        ///         <description>An <paramref name="address"/> of <b>http.soap12://localhost:2929</b> will create an <see cref="WSHttpBinding"/> and update the <paramref name="address"/> to <b>http://localhost:2929</b>.</description>
        ///     </item>
        ///     <item>
        ///         <term><b>http.duplex://</b></term>
        ///         <description>An <paramref name="address"/> of <b>http.duplex://localhost:2929</b> will create an <see cref="WSDualHttpBinding"/> and update the <paramref name="address"/> to <b>http://localhost:2929</b>.</description>
        ///     </item>
        ///     <item>
        ///         <term><b>http.rest://</b></term>
        ///         <description>An <paramref name="address"/> of <b>http.rest://localhost:2929</b> will create an <see cref="WebHttpBinding"/> and update the <paramref name="address"/> to <b>http://localhost:2929</b>.</description>
        ///     </item>
        ///     <item>
        ///         <term><b>net.tcp://</b></term>
        ///         <description>An <paramref name="address"/> of <b>net.tcp://localhost:2929</b> will create an <see cref="NetTcpBinding"/> and leave the <paramref name="address"/> unchanged.</description>
        ///     </item>
        ///     <item>
        ///         <term><b>net.p2p://</b></term>
        ///         <description>An <paramref name="address"/> of <b>net.p2p://localhost:2929</b> will create an <see cref="NetPeerTcpBinding"/> and leave the <paramref name="address"/> unchanged.</description>
        ///     </item>
        ///     <item>
        ///         <term><b>net.pipe://</b></term>
        ///         <description>An <paramref name="address"/> of <b>net.pipe://localhost:2929</b> will create an <see cref="NetNamedPipeBinding"/> and leave the <paramref name="address"/> unchanged.</description>
        ///     </item>
        ///     <item>
        ///         <term><b>net.msmq://</b></term>
        ///         <description>An <paramref name="address"/> of <b>net.msmq://localhost:2929</b> will create an <see cref="NetMsmqBinding"/> and leave the <paramref name="address"/> unchanged.</description>
        ///     </item>
        /// </list>
        /// <para>
        /// The <paramref name="enableSecurity"/> parameter value is ignored Mono deployments since security bindings are not implemented.
        /// </para>
        /// </remarks>
        public static Binding CreateServiceBinding(ref string address, bool enableSecurity)
        {
            address = address.Trim();
            if (string.IsNullOrEmpty(address))
                return null;

            int index = address.IndexOf("://");
            string scheme = address.Substring(0, index >= 0 ? index : address.Length);
            switch (scheme.ToLower())
            {
                case "http":
                case "http.soap11":
                    // Format address.
                    address = address.Replace("http.soap11", "http");
                    // Create binding.
                    BasicHttpBinding soap11Binding = new BasicHttpBinding();

#if !MONO
                    if (enableSecurity)
                    {
                        // Enable security.
                        soap11Binding.Security.Mode = BasicHttpSecurityMode.TransportCredentialOnly;
                        soap11Binding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Windows;
                    }
                    else
                    {
                        // Disable security.
                        soap11Binding.Security.Mode = BasicHttpSecurityMode.None;
                        soap11Binding.Security.Transport.ClientCredentialType = HttpClientCredentialType.None;
                    }
#endif

                    return soap11Binding;
                case "http.soap12":
                    // Format address.
                    address = address.Replace("http.soap12", "http");
                    // Create binding.
                    WSHttpBinding soap12Binding = new WSHttpBinding();

#if !MONO
                    if (enableSecurity)
                    {
                        // Enable security.
                        soap12Binding.Security.Mode = SecurityMode.Transport;
                        soap12Binding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Windows;
                    }
                    else
                    {
                        // Disable security.
                        soap12Binding.Security.Mode = SecurityMode.None;
                        soap12Binding.Security.Transport.ClientCredentialType = HttpClientCredentialType.None;
                    }
#endif

                    return soap12Binding;
                case "http.duplex":
                    // Format address.
                    address = address.Replace("http.duplex", "http");
                    // Create binding.
                    WSDualHttpBinding duplexBinding = new WSDualHttpBinding();

#if !MONO
                    if (enableSecurity)
                    {
                        // Enable security.
                        duplexBinding.Security.Mode = WSDualHttpSecurityMode.Message;
                    }
                    else
                    {
                        // Disable security.
                        duplexBinding.Security.Mode = WSDualHttpSecurityMode.None;
                    }
#endif

                    return duplexBinding;
                case "http.rest":
                    // Format address.
                    address = address.Replace("http.rest", "http");
                    // Create binding.
                    WebHttpBinding restBinding = new WebHttpBinding();

#if !MONO
                    if (enableSecurity)
                    {
                        // Enable security.
                        restBinding.Security.Mode = WebHttpSecurityMode.TransportCredentialOnly;
                        restBinding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Windows;
                    }
                    else
                    {
                        // Disable security.
                        restBinding.Security.Mode = WebHttpSecurityMode.None;
                        restBinding.Security.Transport.ClientCredentialType = HttpClientCredentialType.None;
                    }
#endif

                    return restBinding;
                case "net.tcp":
                    // Create binding.
                    NetTcpBinding tcpBinding = new NetTcpBinding();

#if !MONO
                    if (enableSecurity)
                    {
                        // Enable security.
                        tcpBinding.Security.Mode = SecurityMode.Transport;
                        tcpBinding.Security.Transport.ClientCredentialType = TcpClientCredentialType.Windows;
                    }
                    else
                    {
                        // Disable sercurity.
                        tcpBinding.Security.Mode = SecurityMode.None;
                        tcpBinding.Security.Transport.ClientCredentialType = TcpClientCredentialType.None;
                    }
#endif

                    return tcpBinding;
                case "net.p2p":
                    // Create binding.
#pragma warning disable 612, 618
                    NetPeerTcpBinding p2pBinding = new NetPeerTcpBinding();

#if !MONO
                    if (enableSecurity)
                    {
                        // Enable security.
                        p2pBinding.Security.Mode = SecurityMode.Transport;
                    }
                    else
                    {
                        // Disable security.
                        p2pBinding.Security.Mode = SecurityMode.None;
                    }
#endif

                    return p2pBinding;
                case "net.pipe":
                    // Create binding.
                    NetNamedPipeBinding pipeBinding = new NetNamedPipeBinding();

#if !MONO
                    if (enableSecurity)
                    {
                        // Enable security.
                        pipeBinding.Security.Mode = NetNamedPipeSecurityMode.Transport;
                    }
                    else
                    {
                        // Disable security.
                        pipeBinding.Security.Mode = NetNamedPipeSecurityMode.None;
                    }
#endif

                    return pipeBinding;
                case "net.msmq":
                    // Create binding.
                    NetMsmqBinding msmqBinding = new NetMsmqBinding();

#if !MONO
                    if (enableSecurity)
                    {
                        // Enable security.
                        msmqBinding.Security.Mode = NetMsmqSecurityMode.Transport;
                    }
                    else
                    {
                        // Disable security.
                        msmqBinding.Security.Mode = NetMsmqSecurityMode.None;
                    }
#endif

                    return msmqBinding;
                default:
                    return null;
            }
        }
        public IndicationReporterProxy(Uri address)
        {
            if (address == null)
                throw new ArgumentNullException("address");

            NetMsmqBinding binding = new NetMsmqBinding(NetMsmqSecurityMode.None);
            //TODO set security mode, provide other constructors like InfoServiceProxy has

            channelFactory = new ChannelFactory<IIndicationReporter>(binding, new EndpointAddress(address));
            log.DebugFormat("ChannelFactory created - {0}", address.ToString());
        }
Example #27
0
        internal static bool TryCreate(BindingElementCollection elements, out Binding binding)
        {
            binding = null;
            if (elements.Count > 3)
            {
                return(false);
            }

            SecurityBindingElement security = null;
            BinaryMessageEncodingBindingElement encoding  = null;
            MsmqTransportBindingElement         transport = null;

            foreach (BindingElement element in elements)
            {
                if (element is SecurityBindingElement)
                {
                    security = element as SecurityBindingElement;
                }
                else if (element is TransportBindingElement)
                {
                    transport = element as MsmqTransportBindingElement;
                }
                else if (element is MessageEncodingBindingElement)
                {
                    encoding = element as BinaryMessageEncodingBindingElement;
                }
                else
                {
                    return(false);
                }
            }

            UnifiedSecurityMode mode;

            if (!IsValidTransport(transport, out mode))
            {
                return(false);
            }

            if (encoding == null)
            {
                return(false);
            }

            NetMsmqSecurity netMsmqSecurity;

            if (!TryCreateSecurity(security, mode, out netMsmqSecurity))
            {
                return(false);
            }

            NetMsmqBinding netMsmqBinding = new NetMsmqBinding(netMsmqSecurity);

            netMsmqBinding.InitializeFrom(transport, encoding);
            if (!netMsmqBinding.IsBindingElementsMatch(transport, encoding))
            {
                return(false);
            }

            binding = netMsmqBinding;
            return(true);
        }
 internal static bool TryCreate(BindingElementCollection elements, out Binding binding)
 {
     UnifiedSecurityMode mode;
     NetMsmqSecurity security;
     binding = null;
     if (elements.Count > 3)
     {
         return false;
     }
     SecurityBindingElement sbe = null;
     BinaryMessageEncodingBindingElement encoding = null;
     MsmqTransportBindingElement msmq = null;
     foreach (BindingElement element4 in elements)
     {
         if (element4 is SecurityBindingElement)
         {
             sbe = element4 as SecurityBindingElement;
         }
         else if (element4 is TransportBindingElement)
         {
             msmq = element4 as MsmqTransportBindingElement;
         }
         else if (element4 is MessageEncodingBindingElement)
         {
             encoding = element4 as BinaryMessageEncodingBindingElement;
         }
         else
         {
             return false;
         }
     }
     if (!IsValidTransport(msmq, out mode))
     {
         return false;
     }
     if (encoding == null)
     {
         return false;
     }
     if (!TryCreateSecurity(sbe, mode, out security))
     {
         return false;
     }
     NetMsmqBinding binding2 = new NetMsmqBinding(security);
     binding2.InitializeFrom(msmq, encoding);
     if (!binding2.IsBindingElementsMatch(msmq, encoding))
     {
         return false;
     }
     binding = binding2;
     return true;
 }
Example #29
0
 public void SubmitPurchaseOrder(PurchaseOrder po, string reportOrderStatusTo)
 {
     Orders.Add(po);
     Console.WriteLine("Processing {0} ", po);
     Console.WriteLine("Sending back order status information");
     NetMsmqBinding msmqCallbackBinding = new NetMsmqBinding();
     msmqCallbackBinding.Security.Mode = NetMsmqSecurityMode.None;
     OrderStatusClient client = new OrderStatusClient(msmqCallbackBinding, new EndpointAddress(reportOrderStatusTo));
     // please note that the same transaction that is used to dequeue purchase order is used
     // to send back order status
     using (TransactionScope scope = new TransactionScope(TransactionScopeOption.Required))
     {
         client.OrderStatus(po.PONumber, po.Status);
         scope.Complete();
     }
 }
Example #30
0
        public void SendLetterWcf(UpdateLetter updateLetter)
        {
            var binding = new NetMsmqBinding();

            binding.Security.Mode = NetMsmqSecurityMode.None;

            var endpointAddress = new EndpointAddress("net.msmq://10.2.0.172/private/Message");

            using (ChannelFactory<IMessageService> messageChannelFactory = new ChannelFactory<IMessageService>(binding, endpointAddress))
            {
                try
                {
                    IMessageService messageService = messageChannelFactory.CreateChannel();

                    messageService.GetTest(updateLetter);
                }
                catch (Exception exception)
                {
                    throw exception;
                }
            }

            Flag = true;
        }
Example #31
0
        public static List<NetMsmqBinding> GetNetMsmqBindings(string exeConfigPath)
        {
            var svcSection = Read.Config.ExeConfig.GetServiceModelSection(exeConfigPath);

            var configs = new List<NetMsmqBinding>();
            foreach (
                var section in
                    svcSection.Bindings.NetMsmqBinding.ConfiguredBindings
                        .Cast<NetMsmqBindingElement>())
            {
                var df = new NetMsmqBinding();
                var binding = new NetMsmqBinding
                {
                    Name = section.Name,
                    MaxBufferPoolSize = section.MaxBufferPoolSize > 0 ? section.MaxBufferPoolSize : df.MaxBufferPoolSize,
                    MaxReceivedMessageSize = section.MaxReceivedMessageSize > 0 ? section.MaxReceivedMessageSize : df.MaxReceivedMessageSize,
                    CloseTimeout = section.CloseTimeout != TimeSpan.Zero ? section.CloseTimeout : df.CloseTimeout,
                    OpenTimeout = section.OpenTimeout != TimeSpan.Zero ? section.OpenTimeout : df.OpenTimeout,
                    SendTimeout = section.SendTimeout != TimeSpan.Zero ? section.SendTimeout : df.SendTimeout,
                    ReceiveTimeout =
                        section.ReceiveTimeout != TimeSpan.Zero ? section.ReceiveTimeout : df.ReceiveTimeout,

                    MaxRetryCycles = section.MaxRetryCycles > 0 ? section.MaxRetryCycles : df.MaxRetryCycles,
                    ReceiveRetryCount = section.ReceiveRetryCount > 0 ? section.ReceiveRetryCount : df.ReceiveRetryCount,
                    RetryCycleDelay = section.RetryCycleDelay != TimeSpan.Zero ? section.RetryCycleDelay : df.RetryCycleDelay,
                    TimeToLive = section.TimeToLive != TimeSpan.Zero ? section.TimeToLive : df.TimeToLive,

                    DeadLetterQueue = section.DeadLetterQueue,
                    Durable = section.Durable,
                    ExactlyOnce = section.ExactlyOnce,
                    ReceiveErrorHandling = section.ReceiveErrorHandling,
                    UseSourceJournal = section.UseSourceJournal,
                    UseMsmqTracing = section.UseMsmqTracing,
                    QueueTransferProtocol = section.QueueTransferProtocol,
                    UseActiveDirectory = section.UseActiveDirectory
                };

                var readerQuotasSection = section.ReaderQuotas;
                var readerQuotas = new System.Xml.XmlDictionaryReaderQuotas();
                if (readerQuotasSection != null && readerQuotasSection.MaxDepth > 0)
                {
                    readerQuotas.MaxDepth = readerQuotasSection.MaxDepth;
                    readerQuotas.MaxStringContentLength = readerQuotasSection.MaxStringContentLength;
                    readerQuotas.MaxArrayLength = readerQuotasSection.MaxArrayLength;
                    readerQuotas.MaxBytesPerRead = readerQuotasSection.MaxBytesPerRead;
                    readerQuotas.MaxNameTableCharCount = readerQuotasSection.MaxNameTableCharCount;
                }
                else
                {
                    readerQuotas = null;
                }
                var msmqSecurity = new NetMsmqSecurity {Mode = section.Security.Mode};
                var securityTransportSection = section.Security.Transport;
                var msmqSecurityTransport = new MsmqTransportSecurity
                {
                    MsmqAuthenticationMode = securityTransportSection.MsmqAuthenticationMode,
                    MsmqEncryptionAlgorithm = securityTransportSection.MsmqEncryptionAlgorithm,
                    MsmqProtectionLevel = securityTransportSection.MsmqProtectionLevel,
                    MsmqSecureHashAlgorithm = securityTransportSection.MsmqSecureHashAlgorithm
                };
                var msmqSecurityMessage = new MessageSecurityOverMsmq
                {
                    ClientCredentialType = section.Security.Message.ClientCredentialType
                };
                msmqSecurity.Message = msmqSecurityMessage;
                msmqSecurity.Transport = msmqSecurityTransport;
                binding.Security = msmqSecurity;
                if (readerQuotas != null)
                {
                    binding.ReaderQuotas = readerQuotas;
                }
                configs.Add(binding);

            }
            return configs;
        }