当前位置: 首页>>代码示例>>C#>>正文


C# BinaryMessageEncodingBindingElement.CreateMessageEncoderFactory方法代码示例

本文整理汇总了C#中BinaryMessageEncodingBindingElement.CreateMessageEncoderFactory方法的典型用法代码示例。如果您正苦于以下问题:C# BinaryMessageEncodingBindingElement.CreateMessageEncoderFactory方法的具体用法?C# BinaryMessageEncodingBindingElement.CreateMessageEncoderFactory怎么用?C# BinaryMessageEncodingBindingElement.CreateMessageEncoderFactory使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在BinaryMessageEncodingBindingElement的用法示例。


在下文中一共展示了BinaryMessageEncodingBindingElement.CreateMessageEncoderFactory方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: FileSystemDispatcher_Picks_Up_Existing_Messages

        public void FileSystemDispatcher_Picks_Up_Existing_Messages()
        {
            BinaryMessageEncodingBindingElement element = new BinaryMessageEncodingBindingElement();
            MessageEncoder encoder = element.CreateMessageEncoderFactory().Encoder;

            ServiceBusRuntime dispatchRuntime = new ServiceBusRuntime(new DirectDeliveryCore());
            var subscription = new SubscriptionEndpoint(Guid.NewGuid(), "File System Dispatcher", null, null, typeof(IContract), new FileSystemDispatcher(new ConverterMessageDeliveryWriterFactory(encoder,typeof(IContract)),Config.IncomingFilePath), new PassThroughMessageFilter());
            dispatchRuntime.Subscribe(subscription);

            ServiceBusRuntime listenerRuntime = new ServiceBusRuntime(new DirectDeliveryCore());
            var listener = new ListenerEndpoint(Guid.NewGuid(), "File System Listener", null, null, typeof(IContract), new FileSystemListener(new ConverterMessageDeliveryReaderFactory(encoder, typeof(IContract)),Config.IncomingFilePath, Config.ProcessedFilePath));
            listenerRuntime.AddListener(listener);
            listenerRuntime.Subscribe(new SubscriptionEndpoint(Guid.NewGuid(), "Pass through", null, null, typeof(IContract), new ActionDispatcher((se, md) => { }), new PassThroughMessageFilter()));

            var dispatchTester = new ServiceBusTest(dispatchRuntime);
            var listenerTester = new ServiceBusTest(listenerRuntime);

            string message = "test this thing";

            dispatchTester.StartAndStop(() =>
            {
                dispatchRuntime.PublishOneWay(typeof(IContract), "PublishThis", message);

                listenerTester.WaitForDeliveries(1, TimeSpan.FromSeconds(10), () =>
                {
                });
            });

            dispatchRuntime.RemoveSubscription(subscription);
        }
开发者ID:jezell,项目名称:iserviceoriented,代码行数:30,代码来源:TestFileSystemDispatchersAndListeners.cs

示例2: CreateAndWriteMessage

 private void CreateAndWriteMessage(byte[] bytes) {
   using (var stream = new MemoryStream(bytes, false)) {
     var mebe = new BinaryMessageEncodingBindingElement();
     mebe.MessageVersion = MessageVersion.Soap12;
     mebe.ReaderQuotas.MaxArrayLength = XmlDictionaryReaderQuotas.Max.MaxArrayLength;
     mebe.ReaderQuotas.MaxDepth = XmlDictionaryReaderQuotas.Max.MaxDepth;
     mebe.ReaderQuotas.MaxStringContentLength = XmlDictionaryReaderQuotas.Max.MaxStringContentLength;
     var factory = mebe.CreateMessageEncoderFactory();
     var msg = factory.Encoder.ReadMessage(stream, 1024 * 16);     // I have no idea what header size to give it ...
     WriteMessage(msg);
   }
 }
开发者ID:IdeaBlade,项目名称:DevForce.Utilities,代码行数:12,代码来源:DevForceMessageInspector.cs

示例3: ChatServer

        public ChatServer()
        {
            BinaryMessageEncodingBindingElement element = new BinaryMessageEncodingBindingElement();
            MessageEncoder encoder = element.CreateMessageEncoderFactory().Encoder;

            MessageDeliveryFormatter formatter = new MessageDeliveryFormatter(new ConverterMessageDeliveryReaderFactory(encoder, typeof(IChatService)), new ConverterMessageDeliveryWriterFactory(encoder, typeof(IChatService)));
            _serviceBus = new ServiceBusRuntime(new DirectDeliveryCore() , new WcfManagementService());
            _serviceBus.AddListener(new ListenerEndpoint(Guid.NewGuid(), "Chat Service", "ChatServer", "http://localhost/chatServer", typeof(IChatService), new WcfServiceHostListener()));
            _serviceBus.Subscribe(new SubscriptionEndpoint(Guid.NewGuid(), "No subscribers", "ChatClient", "", typeof(IChatService), new MethodDispatcher(new UnhandledReplyHandler(_serviceBus)), new UnhandledMessageFilter(typeof(SendMessageRequest)), true));
            _serviceBus.UnhandledException+= (o, ex) =>
                {
                    Console.WriteLine("Unhandled Exception: "+ex.ExceptionObject);
                };
        }
开发者ID:jezell,项目名称:iserviceoriented,代码行数:14,代码来源:ChatServer.cs

示例4: TestWithUntypedMessage

        static void TestWithUntypedMessage()
        {
            string baseAddress = SizedTcpDuplexTransportBindingElement.SizedTcpScheme + "://localhost:8000";
            ServiceHost host = new ServiceHost(typeof(Service), new Uri(baseAddress));
            MessageEncodingBindingElement encodingBE = new BinaryMessageEncodingBindingElement();
            Binding binding = new CustomBinding(encodingBE, new SizedTcpDuplexTransportBindingElement());
            host.AddServiceEndpoint(typeof(IUntypedTest), binding, "");
            host.Open();

            Console.WriteLine("Host opened");

            Socket socket = GetConnectedSocket(8000);

            Message input = Message.CreateMessage(MessageVersion.Soap12WSAddressing10, "myAction", "Hello world");
            input.Headers.To = new Uri(baseAddress);
            input.Headers.ReplyTo = new EndpointAddress("http://www.w3.org/2005/08/addressing/anonymous");

            MessageEncoder encoder = encodingBE.CreateMessageEncoderFactory().Encoder;
            BufferManager bufferManager = BufferManager.CreateBufferManager(int.MaxValue, int.MaxValue);
            ArraySegment<byte> encoded = encoder.WriteMessage(input, int.MaxValue, bufferManager, 4);
            Formatting.SizeToBytes(encoded.Count, encoded.Array, 0);

            Console.WriteLine("Sending those bytes:");
            Debugging.PrintBytes(encoded.Array, encoded.Count + encoded.Offset);
            socket.Send(encoded.Array, 0, encoded.Offset + encoded.Count, SocketFlags.None);
            byte[] recvBuffer = new byte[10000];
            int bytesRecvd = socket.Receive(recvBuffer);
            Console.WriteLine("Received {0} bytes", bytesRecvd);
            Debugging.PrintBytes(recvBuffer, bytesRecvd);

            socket.Close();

            Console.WriteLine("Press ENTER to close");
            Console.ReadLine();
            host.Close();
        }
开发者ID:GusLab,项目名称:WCFSamples,代码行数:36,代码来源:Program.cs

示例5: GetMessageText

 /// <summary>
 /// Reads the content of the EventData passed as argument.
 /// </summary>
 /// <param name="eventDataToRead">The EventData to read.</param>
 /// <param name="bodyType">BodyType</param>
 /// <returns>The content of the EventData.</returns>
 public string GetMessageText(EventData eventDataToRead, out BodyType bodyType)
 {
     string eventDataText = null;
     Stream stream = null;
     bodyType = BodyType.Stream;
     if (eventDataToRead == null)
     {
         return null;
     }
     var inboundMessage = eventDataToRead.Clone();
     try
     {
         stream = inboundMessage.GetBody<Stream>();
         if (stream != null)
         {
             var element = new BinaryMessageEncodingBindingElement
             {
                 ReaderQuotas = new XmlDictionaryReaderQuotas
                 {
                     MaxArrayLength = int.MaxValue,
                     MaxBytesPerRead = int.MaxValue,
                     MaxDepth = int.MaxValue,
                     MaxNameTableCharCount = int.MaxValue,
                     MaxStringContentLength = int.MaxValue
                 }
             };
             var encoderFactory = element.CreateMessageEncoderFactory();
             var encoder = encoderFactory.Encoder;
             var stringBuilder = new StringBuilder();
             var eventData = encoder.ReadMessage(stream, MaxBufferSize);
             using (var reader = eventData.GetReaderAtBodyContents())
             {
                 // The XmlWriter is used just to indent the XML eventData
                 var settings = new XmlWriterSettings { Indent = true };
                 using (var writer = XmlWriter.Create(stringBuilder, settings))
                 {
                     writer.WriteNode(reader, true);
                 }
             }
             eventDataText = stringBuilder.ToString();
             bodyType = BodyType.Wcf;
         }
     }
     catch (Exception)
     {
         inboundMessage = eventDataToRead.Clone();
         try
         {
             stream = inboundMessage.GetBody<Stream>();
             if (stream != null)
             {
                 var element = new BinaryMessageEncodingBindingElement
                 {
                     ReaderQuotas = new XmlDictionaryReaderQuotas
                     {
                         MaxArrayLength = int.MaxValue,
                         MaxBytesPerRead = int.MaxValue,
                         MaxDepth = int.MaxValue,
                         MaxNameTableCharCount = int.MaxValue,
                         MaxStringContentLength = int.MaxValue
                     }
                 };
                 var encoderFactory = element.CreateMessageEncoderFactory();
                 var encoder = encoderFactory.Encoder;
                 var eventData = encoder.ReadMessage(stream, MaxBufferSize);
                 using (var reader = eventData.GetReaderAtBodyContents())
                 {
                     eventDataText = reader.ReadString();
                 }
                 bodyType = BodyType.Wcf;
             }
         }
         catch (Exception)
         {
             try
             {
                 if (stream != null)
                 {
                     try
                     {
                         stream.Seek(0, SeekOrigin.Begin);
                         var serializer = new CustomDataContractBinarySerializer(typeof(string));
                         eventDataText = serializer.ReadObject(stream) as string;
                         bodyType = BodyType.String;
                     }
                     catch (Exception)
                     {
                         try
                         {
                             stream.Seek(0, SeekOrigin.Begin);
                             using (var reader = new StreamReader(stream))
                             {
                                 eventDataText = reader.ReadToEnd();
                                 if (eventDataText.ToCharArray().GroupBy(c => c).
//.........这里部分代码省略.........
开发者ID:abombss,项目名称:ServiceBusExplorer,代码行数:101,代码来源:ServiceBusHelper.cs

示例6: ListenerControl

 public ListenerControl(WriteToLogDelegate writeToLog,
                        Func<Task> stopLog,
                        Action startLog,
                        ServiceBusHelper serviceBusHelper, 
                        EntityDescription entityDescription)
 {
     this.logStopped = false;
     Task.Factory.StartNew(AsyncTrackMessage).ContinueWith(t =>
     {
         if (t.IsFaulted && t.Exception != null)
         {
             writeToLog(t.Exception.Message);
         }
     });
     this.writeToLog = writeToLog;
     this.stopLog = stopLog;
     this.startLog = startLog;
     this.serviceBusHelper = serviceBusHelper;
     this.entityDescription = entityDescription;
     var element = new BinaryMessageEncodingBindingElement();
     var encoderFactory = element.CreateMessageEncoderFactory();
     encoder = encoderFactory.Encoder;
     InitializeComponent();
     InitializeControls();
     Disposed += ListenerControl_Disposed;
     if (entityDescription is SubscriptionDescription)
     {
         grouperEntityInformation.GroupTitle = "Subscription Information";
     }
 }
开发者ID:paolosalvatori,项目名称:ServiceBusExplorer,代码行数:30,代码来源:ListenerControl.cs

示例7: Send

        public void Send(Message message)
        {
            var bufferedCopy = message.CreateBufferedCopy(int.MaxValue);
            var messageToStream = bufferedCopy.CreateMessage();

            var binaryMessageEncodingBindingElement = new BinaryMessageEncodingBindingElement();
            var messageEncoderFactory = binaryMessageEncodingBindingElement.CreateMessageEncoderFactory();
            var messageEncoder = messageEncoderFactory.Encoder;

            byte[] messageData;
            using (var memoryStream = new MemoryStream())
            {
                messageEncoder.WriteMessage(messageToStream, memoryStream);
                messageData = memoryStream.ToArray();
            }

            this.queue.Send(new ServiceOperationMessage {OperationData = messageData});
        }
开发者ID:kusl,项目名称:rudymq,代码行数:18,代码来源:OutputChannel.cs

示例8: TryReceive

        public bool TryReceive(TimeSpan timeout, out Message message)
        {
            this.ThrowIfDisposed();

            message = null;
            if (this.State == CommunicationState.Closed || this.State == CommunicationState.Closing)
                return true;

            var serviceOperationMessage = ((Queue)this.queue).Receive<ServiceOperationMessage>();
            if (serviceOperationMessage == null) return false;

            var binaryMessageEncodingBindingElement = new BinaryMessageEncodingBindingElement();
            var messageEncoderFactory = binaryMessageEncodingBindingElement.CreateMessageEncoderFactory();
            var messageEncoder = messageEncoderFactory.Encoder;

            using (var memoryStream = new MemoryStream(serviceOperationMessage.OperationData))
            {
                var streamedMessage = messageEncoder.ReadMessage(memoryStream, int.MaxValue);
                var bufferedCopy = streamedMessage.CreateBufferedCopy(int.MaxValue);
                message = bufferedCopy.CreateMessage();
            }

            if (!message.Headers.Any(x => x.Name == "To" && x.Namespace == "http://www.w3.org/2005/08/addressing"))
                message.Headers.Add(MessageHeader.CreateHeader("To", "http://www.w3.org/2005/08/addressing",
                                                               this.LocalAddress.Uri));

            return true;
        }
开发者ID:kusl,项目名称:rudymq,代码行数:28,代码来源:InputChannel.cs


注:本文中的BinaryMessageEncodingBindingElement.CreateMessageEncoderFactory方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。