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


C# Message.GetReaderAtBodyContents方法代码示例

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


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

示例1: Execute

        /// <summary>
        /// Executes the request message on the target system and returns a response message.
        /// If there isn’t a response, this method should return null
        /// </summary>
        public Message Execute(Message message, TimeSpan timeout)
        {
            if (message.Headers.Action != "Submit")
                throw new ApplicationException("Unexpected Message Action");

            //Parse the request message to extract the string and get out the body to send to the socket
            XmlDictionaryReader rdr = message.GetReaderAtBodyContents();
            rdr.Read();
            string input = rdr.ReadElementContentAsString();

            //Interact with the socket
            this.Connection.Client.SendData(input);
            string output = this.Connection.Client.ReceiveData();
            Debug.WriteLine(output);

            //Produce the response message
            StringBuilder outputString = new StringBuilder();
            XmlWriterSettings settings = new XmlWriterSettings();
            settings.OmitXmlDeclaration = true;
            XmlWriter replywriter = XmlWriter.Create(outputString, settings);
            replywriter.WriteStartElement("SendResponse", "http://acme.wcf.lob.paymentapplication/");
            replywriter.WriteStartElement("SendResult");
            replywriter.WriteString(Convert.ToBase64String(UTF8Encoding.UTF8.GetBytes(output)));
            replywriter.WriteEndElement();
            replywriter.WriteEndElement();
            replywriter.Close();
            XmlReader replyReader = XmlReader.Create(new StringReader(outputString.ToString()));

            Message response = Message.CreateMessage(MessageVersion.Default, "Submit/Response", replyReader);
            return response;
        }
开发者ID:andychops,项目名称:Libraries,代码行数:35,代码来源:SocketAdapterOutboundHandler.cs

示例2: DeserializeMessageWithPayload

 public object DeserializeMessageWithPayload(Message messageWithPayload, Type expectedType)
 {
     if (messageWithPayload.IsEmpty)
     {
         return null;
     }
     if (typeof(IXmlSerializable).IsAssignableFrom(expectedType))
     {
         var serializable = (IXmlSerializable)Activator.CreateInstance(expectedType);
         serializable.ReadXml(messageWithPayload.GetReaderAtBodyContents());
         return serializable;
     }
     var xs = new XmlSerializer(expectedType);
     return xs.Deserialize(messageWithPayload.GetReaderAtBodyContents());
 }
开发者ID:SzymonPobiega,项目名称:WS-Man.Net,代码行数:15,代码来源:MessageFactory.cs

示例3: CreateCoordinationContextResponse

 public CreateCoordinationContextResponse(Message message, Microsoft.Transactions.Wsat.Protocol.ProtocolVersion protocolVersion) : this(protocolVersion)
 {
     if (message.IsEmpty)
     {
         throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidMessageException(Microsoft.Transactions.SR.GetString("InvalidMessageBody")));
     }
     XmlDictionaryReader readerAtBodyContents = message.GetReaderAtBodyContents();
     using (readerAtBodyContents)
     {
         this.ReadFrom(readerAtBodyContents);
         try
         {
             message.ReadFromBodyContentsToEnd(readerAtBodyContents);
         }
         catch (XmlException exception)
         {
             throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidMessageException(Microsoft.Transactions.SR.GetString("InvalidMessageBody"), exception));
         }
     }
     try
     {
         this.IssuedToken = CoordinationServiceSecurity.GetIssuedToken(message, this.CoordinationContext.Identifier, protocolVersion);
     }
     catch (XmlException exception2)
     {
         throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidMessageException(exception2.Message, exception2));
     }
 }
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:28,代码来源:CreateCoordinationContextResponse.cs

示例4: BeforeSendRequest

        public object BeforeSendRequest(ref Message request, IClientChannel channel)
        {
            if (!request.IsEmpty)
            {
                XmlReader bodyReader = request.GetReaderAtBodyContents().ReadSubtree();

                MemoryStream stream = new MemoryStream();
                XmlWriter writer = XmlWriter.Create(stream);

                if (transform == null)
                {
                    transform = new XslCompiledTransform(true);
                    var reader = XmlReader.Create(new StringReader(Properties.Resources.XmlCleaner));
                    transform.Load(reader);
                }
                transform.Transform(bodyReader, writer);

                stream.Flush();
                stream.Seek(0, SeekOrigin.Begin);

                bodyReader = XmlReader.Create(stream);

                Message changedMessage = Message.CreateMessage(request.Version, null, bodyReader);
                changedMessage.Headers.CopyHeadersFrom(request.Headers);
                changedMessage.Properties.CopyProperties(request.Properties);
                request = changedMessage;
            }

            return null;
        }
开发者ID:spardo,项目名称:dotnet37signals,代码行数:30,代码来源:RestClientMessageInspector.cs

示例5: DeserializeBody

 public static byte[] DeserializeBody(Message message)
 {
     using (XmlDictionaryReader bodyReader = message.GetReaderAtBodyContents()) {
         bodyReader.ReadStartElement("Binary");
         return bodyReader.ReadContentAsBase64();
     }
 }
开发者ID:yonglehou,项目名称:JsonRpc.ServiceModel,代码行数:7,代码来源:DispatcherUtils.cs

示例6: ReadMessage

 public static CreateSequenceInfo ReadMessage(MessageVersion messageVersion, ReliableMessagingVersion reliableMessagingVersion, ISecureConversationSession securitySession, Message message, MessageHeaders headers)
 {
     CreateSequenceInfo info;
     if (message.IsEmpty)
     {
         string reason = System.ServiceModel.SR.GetString("NonEmptyWsrmMessageIsEmpty", new object[] { WsrmIndex.GetCreateSequenceActionString(reliableMessagingVersion) });
         Message faultReply = WsrmUtilities.CreateCSRefusedProtocolFault(messageVersion, reliableMessagingVersion, reason);
         throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(WsrmMessageInfo.CreateInternalFaultException(faultReply, reason, new ProtocolException(reason)));
     }
     using (XmlDictionaryReader reader = message.GetReaderAtBodyContents())
     {
         info = CreateSequence.Create(messageVersion, reliableMessagingVersion, securitySession, reader);
         message.ReadFromBodyContentsToEnd(reader);
     }
     info.SetMessageId(messageVersion, headers);
     info.SetReplyTo(messageVersion, headers);
     if (info.AcksTo.Uri != info.ReplyTo.Uri)
     {
         string str2 = System.ServiceModel.SR.GetString("CSRefusedAcksToMustEqualReplyTo");
         Message message3 = WsrmUtilities.CreateCSRefusedProtocolFault(messageVersion, reliableMessagingVersion, str2);
         throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(WsrmMessageInfo.CreateInternalFaultException(message3, str2, new ProtocolException(str2)));
     }
     info.to = message.Headers.To;
     if ((info.to == null) && (messageVersion.Addressing == AddressingVersion.WSAddressing10))
     {
         info.to = messageVersion.Addressing.AnonymousUri;
     }
     return info;
 }
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:29,代码来源:CreateSequenceInfo.cs

示例7: CompressMessage

 public Message CompressMessage(Message sourceMessage)
 {
     byte[] buffer;
     MessageBuffer messageBuffer = sourceMessage.CreateBufferedCopy(int.MaxValue);
     sourceMessage.Close();
     sourceMessage = messageBuffer.CreateMessage();
     using (XmlDictionaryReader reader1 = sourceMessage.GetReaderAtBodyContents())
     {
         buffer = Encoding.UTF8.GetBytes(reader1.ReadOuterXml());
     }
     if (buffer.Length < this.MinMessageSize)
     {
         sourceMessage.Close();
         return messageBuffer.CreateMessage();
     }
     byte[] compressedData = DataCompressor.Compress(buffer);
     string copressedBody = CreateCompressedBody(compressedData);
     XmlTextReader reader = new XmlTextReader(new StringReader(copressedBody), new NameTable());
     Message compressedMessage = Message.CreateMessage(sourceMessage.Version, null, (XmlReader)reader);
     compressedMessage.Headers.CopyHeadersFrom(sourceMessage);
     compressedMessage.Properties.CopyProperties(sourceMessage.Properties);
     compressedMessage.AddCompressionHeader(this.DataCompressor.Algorithm);
     sourceMessage.Close();
     return compressedMessage;
 }
开发者ID:huoxudong125,项目名称:WCF-Demo,代码行数:25,代码来源:MessageCompressor.cs

示例8: SelectOperationInternal

        private string SelectOperationInternal(Message message)
        {
            byte[] rawBody;
            using (XmlDictionaryReader bodyReader = message.GetReaderAtBodyContents()) {
                bodyReader.ReadStartElement("Binary");
                rawBody = bodyReader.ReadContentAsBase64();
            }

            string operation = null;
            using (var bodyReader = new JsonTextReader(new StreamReader(new MemoryStream(rawBody)))) {
                while (bodyReader.Read()) {
                    if (bodyReader.TokenType == JsonToken.PropertyName) {
                        string propertyName = (string)bodyReader.Value;
                        if (propertyName.Equals("method", StringComparison.Ordinal)) {
                            if (!bodyReader.Read() || bodyReader.TokenType != JsonToken.String)
                                throw new InvalidOperationException("Invalid message format.");

                            operation = (string)bodyReader.Value;
                            break;
                        }
                    }
                }
            }

            return operation;
        }
开发者ID:yonglehou,项目名称:JsonRpc.ServiceModel,代码行数:26,代码来源:JsonRpcOperationSelector.cs

示例9: Deserialize

        public void Deserialize(OperationDescription operation, Dictionary<string, int> parameterNames, Message message, object[] parameters)
        {
            object bodyFormatProperty;
            if (!message.Properties.TryGetValue(WebBodyFormatMessageProperty.Name, out bodyFormatProperty) ||
                (bodyFormatProperty as WebBodyFormatMessageProperty).Format != WebContentFormat.Raw)
            {
                throw new InvalidOperationException(
                    "Incoming messages must have a body format of Raw. Is a ContentTypeMapper set on the WebHttpBinding?");
            }

            var bodyReader = message.GetReaderAtBodyContents();
            bodyReader.ReadStartElement("Binary");
            byte[] rawBody = bodyReader.ReadContentAsBase64();
            using (var ms = new MemoryStream(rawBody))
            using (var sr = new StreamReader(ms))
            {
                var serializer = new System.Xml.Serialization.XmlSerializer(operation.Messages[0].Body.Parts[0].Type);
                if (parameters.Length == 1)
                {
                    // single parameter, assuming bare
                    parameters[0] = serializer.Deserialize(sr);
                }
                else
                {
                    throw new InvalidOperationException("We don't support multiple xml parameters");
                }
                sr.Close();
                ms.Close();
            }
        }
开发者ID:ElementalCrisis,项目名称:jmmserver,代码行数:30,代码来源:XmlSerializer.cs

示例10: DeserializeReply

        public object DeserializeReply(Message message, object[] parameters)
        {
            object bodyFormatProperty;
            if (!message.Properties.TryGetValue(WebBodyFormatMessageProperty.Name, out bodyFormatProperty) ||
                (bodyFormatProperty as WebBodyFormatMessageProperty).Format != WebContentFormat.Raw)
            {
                throw new InvalidOperationException("Incoming messages must have a body format of Raw. Is a ContentTypeMapper set on the WebHttpBinding?");
            }

            var bodyReader = message.GetReaderAtBodyContents();
            var serializer = new JsonSerializer();
            bodyReader.ReadStartElement("Binary");
            byte[] body = bodyReader.ReadContentAsBase64();

            // I tried to use a converter for this. But I failed miserably :-)
            body = WorkAroundCrm15891(body);

            using (var ms = new MemoryStream(body))
            {
                using (var sr = new StreamReader(ms))
                {
                    Type returnType = this._operation.Messages[1].Body.ReturnValue.Type;
                    if (returnType == typeof (EmptyResult))
                    {
                        // If the result of the API cannot be parsed, you can use EmptyResult
                        // as a result. In this case the body is ignored.
                        return new EmptyResult();
                    }
                    var result = serializer.Deserialize(sr, returnType);
                    return result;
                }
            }
        }
开发者ID:Chirojeugd-Vlaanderen,项目名称:civicrm.net,代码行数:33,代码来源:JsonClientFormatter.cs

示例11: WriteMessage

        public override ArraySegment<byte> WriteMessage(Message message,
      int maxMessageSize, BufferManager bufferManager, int messageOffset)
        {
            String bodyContent = null;

              lastMessage = message.Headers.Action;

              XmlDictionaryReader reader = message.GetReaderAtBodyContents();
              while (reader.Read())
              {
            if (reader.Name == "request")
            {
              bodyContent = reader.ReadElementContentAsString();
              break;
            }
              }
              reader.Close();

              byte[] messageBytes = System.Text.Encoding.UTF8.GetBytes(bodyContent);

              int totalLength = messageBytes.Length + messageOffset;
              byte[] totalBytes = bufferManager.TakeBuffer(totalLength);
              Array.Copy(messageBytes, 0,
            totalBytes, messageOffset, messageBytes.Length);

              ArraySegment<byte> buffer =
            new ArraySegment<byte>(
              totalBytes, messageOffset, messageBytes.Length);

              return buffer;
        }
开发者ID:gitlabuser,项目名称:warehouse,代码行数:31,代码来源:SerialMessageEncoder.cs

示例12: DeserializeRequest

        public void DeserializeRequest(Message message, object[] parameters)
        {
            object bodyFormatProperty;
            if (!message.Properties.TryGetValue(WebBodyFormatMessageProperty.Name, out bodyFormatProperty) ||
                (bodyFormatProperty as WebBodyFormatMessageProperty).Format != WebContentFormat.Raw)
            {
                throw new InvalidOperationException("Incoming messages must have a body format of Raw. Is a ContentTypeMapper set on the WebHttpBinding?");
            }

            XmlDictionaryReader bodyReader = message.GetReaderAtBodyContents();
            bodyReader.ReadStartElement("Binary");
            byte[] rawBody = bodyReader.ReadContentAsBase64();
            MemoryStream ms = new MemoryStream(rawBody);

            StreamReader sr = new StreamReader(ms);
            JsonSerializer serializer = new JsonSerializer
            {
                PreserveReferencesHandling = PreserveReferencesHandling.Objects
            };

            if (parameters.Length == 1)
            {
                // single parameter, assuming bare
                parameters[0] = serializer.Deserialize(sr, this.operation.Messages[0].Body.Parts[0].Type);
            }
            else
            {
                // multiple parameter, needs to be wrapped
                JsonReader reader = new JsonTextReader(sr);
                reader.Read();
                if (reader.TokenType != JsonToken.StartObject)
                {
                    throw new InvalidOperationException("Input needs to be wrapped in an object");
                }

                reader.Read();
                while (reader.TokenType == JsonToken.PropertyName)
                {
                    string parameterName = reader.Value as string;
                    reader.Read();
                    if (this.parameterNames.ContainsKey(parameterName))
                    {
                        int parameterIndex = this.parameterNames[parameterName];
                        parameters[parameterIndex] = serializer.Deserialize(reader, this.operation.Messages[0].Body.Parts[parameterIndex].Type);
                    }
                    else
                    {
                        reader.Skip();
                    }

                    reader.Read();
                }

                reader.Close();
            }

            sr.Close();
            ms.Close();
        }
开发者ID:thomasgalliker,项目名称:EmployeeManagement,代码行数:59,代码来源:NewtonsoftJsonDispatchFormatter.cs

示例13: Execute

        /// <summary>
        /// Executes the request message on the target system and returns a response message.
        /// If there isn’t a response, this method should return null
        /// </summary>
        public Message Execute(Message message, TimeSpan timeout)
        {
            string action = message.Headers.Action;
            string responseAction = action + "Response";

            var operation = ParseAction(action);

            string operationType = operation.Item1;
            string operationTarget = operation.Item2;

            Message result = null;

            using (var bodyReader = message.GetReaderAtBodyContents())
            {
                using (var connection = Connection.CreateDbConnection())
                {
                    connection.Open();

                    var scopeOptions = this.Connection.ConnectionFactory.Adapter.UseAmbientTransaction ? TransactionScopeOption.Required : TransactionScopeOption.RequiresNew;

                    using (var scope = new TransactionScope(scopeOptions, new TransactionOptions { IsolationLevel = Connection.ConnectionFactory.Adapter.IsolationLevel, Timeout = timeout }))
                    {
                        if (operationType == "Execute")
                        {
                            var commandBuilder = Connection.CreateDbCommandBuilder(string.Empty, connection);
                            result = DbHelpers.Execute(bodyReader, connection, operationTarget, commandBuilder.GetType(), responseAction);
                        }
                        else if (operationType == "MultiExecute")
                        {
                            var commandBuilder = Connection.CreateDbCommandBuilder(string.Empty, connection);
                            result = DbHelpers.MultiExecute(bodyReader, connection, operationTarget, commandBuilder.GetType(), responseAction);
                        }
                        else if (operationType == "Create")
                        {
                            var commandBuilder = Connection.CreateDbCommandBuilder(operationTarget, connection);
                            result = DbHelpers.Create(bodyReader, connection, operationType, commandBuilder, responseAction);
                        }
                        else if (operationType == "Read")
                        {
                            result = DbHelpers.Read(bodyReader, connection, responseAction);
                        }
                        else if (operationType == "Update")
                        {
                            var commandBuilder = Connection.CreateDbCommandBuilder(operationTarget, connection);
                            result = DbHelpers.Update(bodyReader, connection, operationType, commandBuilder, responseAction);
                        }
                        else if (operationType == "Delete")
                        {
                            var commandBuilder = Connection.CreateDbCommandBuilder(operationTarget, connection);
                            result = DbHelpers.Delete(bodyReader, connection, operationType, commandBuilder, responseAction);
                        }

                        scope.Complete();
                    }
                }
            }

            return result;
        }
开发者ID:mi-tettamanti,项目名称:mercury-contrib-adapters,代码行数:63,代码来源:AdoNetAdapterOutboundHandler.cs

示例14: MessageToParts

		protected override object [] MessageToParts (MessageDescription md, Message message)
		{
			if (message.IsEmpty)
				return null;
				
			XmlDictionaryReader r = message.GetReaderAtBodyContents ();
			return (object []) GetSerializer (md.Body).Deserialize (r);
		}
开发者ID:nickchal,项目名称:pash,代码行数:8,代码来源:XmlMessagesFormatter.cs

示例15: ReadRequest

		public WstRequestSecurityToken ReadRequest (Message msg)
		{
			using (WSTrustRequestSecurityTokenReader reader =
				new WSTrustRequestSecurityTokenReader (msg.GetReaderAtBodyContents (), serializer)) {
				reader.Read ();
				return reader.Value;
			}
		}
开发者ID:alesliehughes,项目名称:olive,代码行数:8,代码来源:WSTrustSecurityTokenService.cs


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