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


C# Message.GetBody方法代码示例

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


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

示例1: GetMessage

        public Model.Message GetMessage(Message message)
        {
            var msgBytes = message.GetBody<byte[]>();
            var content = Encoding.UTF8.GetString(msgBytes);

            return JsonConvert.DeserializeObject<Model.Message>(content);
        }
开发者ID:GeorgiMateev,项目名称:Newsfeed,代码行数:7,代码来源:NewsfeedManager.cs

示例2: Request

        public Message Request(Message req)
        {
            ServiceResponse resp = new ServiceResponse();

            try
            {

                ServiceRequest servReq = req.GetBody<ServiceRequest>();
                servReq.Password = req.Headers.GetHeader<string>("Password", "");
                servReq.ServiceAction = req.Headers.GetHeader<string>("ServiceAction", "");

                servReq.Password = Decrypt(servReq.Password);
                servReq.Data = Decrypt(servReq.Data);

                resp.ErrorNumber = 0;
                resp.ErrorMessage = string.Empty;
                resp.IsSuccessful = true;
                //resp.Data = "Brian Spencer Test";
                resp.Data = string.Format("Action: {0}; Username: {1}; Password: {2}; Data: {3}", servReq.ServiceAction, servReq.UserName, servReq.Password, servReq.Data);

            }
            catch (Exception ex)
            {
                resp.ErrorNumber = 9000;
                resp.ErrorMessage = ex.Message;
                resp.IsSuccessful = false;
                resp.Data = "Error";
            }

            MessageVersion ver = OperationContext.Current.IncomingMessageVersion;
            return Message.CreateMessage(ver, "http://dis.lashgroup.com/Response", resp);
        }
开发者ID:bespencer1,项目名称:Csharp,代码行数:32,代码来源:DataIntegrationService.svc.cs

示例3: MessageItem

        public MessageItem(Message message)
        {
            Action = message.Headers.Action;

            Stream body = message.GetBody<Stream>();

            using (var reader = new StreamReader(body))
                Data = reader.ReadToEnd();
        }
开发者ID:mi-tettamanti,项目名称:mercury-contrib-adapters,代码行数:9,代码来源:Service.cs

示例4: ConcatStrings

		public Message ConcatStrings (Message request)
		{
			string str = string.Empty;

			string [] inputStrings = request.GetBody<string []> ();
			for (int i = 0; i < inputStrings.Length; i++)
				str += inputStrings [i];

			Message response = Message.CreateMessage (request.Version, ReplyAction, str);
			return response;
		}
开发者ID:nickchal,项目名称:pash,代码行数:11,代码来源:UntypedMessageTester.cs

示例5: SubscribeToCardSwipe

        public void SubscribeToCardSwipe(Message message)
        {
            var current = OperationContext.Current.GetCallbackChannel<IWebCardReaderEventsCallBack>();

            if (message == null || current==null)
            {
                throw new ArgumentNullException("message or current is null");
            }

            WebSocketMessageProperty property =
                (WebSocketMessageProperty)message.Properties["WebSocketMessageProperty"];
            WebSocketContext context = property.WebSocketContext;

            var queryParameters = HttpUtility.ParseQueryString(context.RequestUri.Query);
            string content = string.Empty;

            if (!message.IsEmpty)
            {
                byte[] body = message.GetBody<byte[]>();
                content = Encoding.UTF8.GetString(body);

                //client needs to send this to ensure connection is open.
                if(content== "KeepAlive")
                {
                    return;
                }
            }

            // Do something with the content/queryParams
            // ...

            string str = null;
            if (string.IsNullOrEmpty(content)) // Connection open message
            {
                str = "Opening connection from host " + queryParameters["Name"].ToString();
            }
            else // Message received from client
            {
                str = "Received message: " + content;
            }

            var hostName = queryParameters["Name"].ToString();

            if (!_webCardReaderSubscription.ContainsKey(hostName) && current!=null)
            {
                _webCardReaderSubscription.Add(hostName, current);
            }
            else
            {
                _webCardReaderSubscription[hostName] = current;
            }

            // current.SendCardSwipe(CreateMessage(str));
        }
开发者ID:goodwillguy,项目名称:DeviceManagerService,代码行数:54,代码来源:CardReaderService.cs

示例6: SendMessage

        public async Task SendMessage(Message message)
        {
            if (message.IsEmpty) return;

            byte[] body = message.GetBody<byte[]>();
            WebSocketMessageProperty property = 
                (WebSocketMessageProperty)message.Properties[webSocketMessageProperty];
            WebSocketMessageType type = property.MessageType;

            IServiceCallback callback = 
                OperationContext.Current.GetCallbackChannel<IServiceCallback>();

            IChannel channel = (IChannel)callback;
            channel.Faulted += channel_Faulted;
            channel.Closed += channel_Closed;

            if (channel.State == CommunicationState.Opened)
                await callback.ReceiveMessage(CreateMessage(body, type));
        }
开发者ID:tewarid,项目名称:NetTools,代码行数:19,代码来源:Service.cs

示例7: GetResponseMessageStream

        public Stream GetResponseMessageStream(Message message)
        {
            if (message == null)
            {
                throw FxTrace.Exception.ArgumentNull("message");
            }

            ThrowIfMismatchedMessageVersion(message);

            if (!ByteStreamMessage.IsInternalByteStreamMessage(message))
            {
                return null;
            }

            return message.GetBody<Stream>();
        }
开发者ID:iskiselev,项目名称:JSIL.NetFramework,代码行数:16,代码来源:ByteStreamMessageEncoder.cs

示例8: 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)
        {
            var generator = new NameGenerator(message,
                Connection.ConnectionFactory.ConnectionUri.Path, Connection.ConnectionFactory.ConnectionUri.FileName);

            string sourcePath = new Uri(message.Headers.Action).LocalPath;

            string targetFolder = generator.Folder;
            string targetPath = Path.Combine(targetFolder, generator.FileName).Replace('\\', '/');

            if (!targetPath.StartsWith("/"))
                targetPath = string.Concat("/", targetPath);

            var client = Connection.Client;

            if (!client.DirectoryExists(targetFolder))
                client.CreateDirectory(targetFolder);

            Stream outputStream = null;

            switch (Connection.ConnectionFactory.Adapter.OverwriteAction)
            {
                case OverwriteAction.None:
                    if (client.FileExists(targetPath))
                        throw new FtpException(string.Format("The file '{0}' already exists.", targetPath));

                    outputStream = client.OpenWrite(targetPath);
                    break;
                case OverwriteAction.Replace:
                    outputStream = client.OpenWrite(targetPath);
                    break;
                case OverwriteAction.Append:
                    outputStream = client.OpenAppend(targetPath);
                    break;
            }

            using (outputStream)
            {
                var inputStream = message.GetBody<Stream>();
                inputStream.CopyTo(outputStream);

                return Message.CreateMessage(MessageVersion.Default, string.Empty);
            }
        }
开发者ID:mi-tettamanti,项目名称:mercury-contrib-adapters,代码行数:48,代码来源:FtpAdapterOutboundHandler.cs

示例9: AddCustomer

        Message AddCustomer(Message message)
        {
            Message response = null;
            HttpRequestMessageProperty requestProperties = message.Properties[HttpRequestMessageProperty.Name] as HttpRequestMessageProperty;

            HttpResponseMessageProperty responseProperties = new HttpResponseMessageProperty();

            Console.WriteLine("Received " + requestProperties.Method + " for Customer.");
            Customer customer = message.GetBody<Customer>();

            Console.WriteLine("\tCustomer Data - Name: " + customer.Name + " Address: " + customer.Address);
            if (customer != null)
            {
                this.nextId += 1;
                this.customerList[nextId.ToString()] = customer;

                Uri collectionUri = message.Properties.Via;

                responseProperties.StatusCode = HttpStatusCode.Created;
                responseProperties.Headers[ HttpResponseHeader.Location ] = new Uri( collectionUri, this.nextId.ToString() ).ToString();
            }
            else
            {
                responseProperties.StatusCode = HttpStatusCode.BadRequest;
            }

            responseProperties.SuppressEntityBody = true;
            response = Message.CreateMessage(message.Version, message.Headers.Action, String.Empty);
            response.Properties[HttpResponseMessageProperty.Name] = responseProperties;

            return response;

        }
开发者ID:spzenk,项目名称:sfdocsamples,代码行数:33,代码来源:CustomerService.cs

示例10: UpdateCustomer

        Message UpdateCustomer(Message message)
        {
            Message response = null;

            HttpRequestMessageProperty requestProperties = message.Properties[HttpRequestMessageProperty.Name] as HttpRequestMessageProperty;
            HttpResponseMessageProperty responseProperties = new HttpResponseMessageProperty();

            Uri endpointUri = OperationContext.Current.EndpointDispatcher.EndpointAddress.Uri;
            string id = CustomerIdFromRequestUri( message.Properties.Via, endpointUri );

            Console.WriteLine("Received " + requestProperties.Method + " for Customer.");
            Customer customer = message.GetBody<Customer>();
            Console.WriteLine("\tCustomer Data - Name: " + customer.Name + " Address: " + customer.Address);
            
            if (customer != null)
            {
                if (!customerList.ContainsKey(id))
                {
                    responseProperties.StatusCode = HttpStatusCode.NotFound;
                }
                else
                {
                    customerList[id] = customer;
                    responseProperties.StatusCode = HttpStatusCode.OK;
                }
            }
            else
            {
                responseProperties.StatusCode = HttpStatusCode.BadRequest;
            }

            responseProperties.SuppressEntityBody = true;
            response = Message.CreateMessage(message.Version, message.Headers.Action, String.Empty);
            response.Properties[HttpResponseMessageProperty.Name] = responseProperties;

            return response;
        }
开发者ID:spzenk,项目名称:sfdocsamples,代码行数:37,代码来源:CustomerService.cs

示例11: CreateMessageContent

        private static HttpContent CreateMessageContent(Message message, bool suppressEntityBody)
        {
            Fx.Assert(message != null, "The 'message' parameter should not be null.");

            if (suppressEntityBody || message.IsEmpty)
            {
                return new ByteArrayContent(EmptyArray<byte>.Instance);
            }

            return new StreamContent(message.GetBody<Stream>());
        }
开发者ID:nlh774,项目名称:DotNetReferenceSource,代码行数:11,代码来源:MessageExtensionMethods.cs

示例12: ConvertGetResponseToIdmResource

        private static IdmResource ConvertGetResponseToIdmResource(Message getResponseMsg)
        {
            BaseObjectSearchResponse getResponseObj =
                getResponseMsg.GetBody<BaseObjectSearchResponse>(new SoapXmlSerializer(typeof(BaseObjectSearchResponse)));

            var resource = new IdmResource();

            foreach (XmlNode partialAttribute in getResponseObj.PartialAttribute)
                foreach (XmlNode attribute in partialAttribute.ChildNodes)
                    BuildAttribute(attribute, resource);
            return resource;
        }
开发者ID:sunmorgus,项目名称:ms-idm-net,代码行数:12,代码来源:IdmNetClient.cs

示例13: AssertIsEqualMessage

 private void AssertIsEqualMessage(Message message1, Message message2)
 {
     Data data1 = message1.GetBody<Data>();
      Data data2 = message2.GetBody<Data>();
      Assert.AreEqual(data1.Value, data2.Value);
 }
开发者ID:modulexcite,项目名称:WcfEx,代码行数:6,代码来源:TestMessageCodec.cs

示例14: ConvertPullResponseToPagedSearchResults

 private static PagedSearchResults ConvertPullResponseToPagedSearchResults(PagingContext pagingContext,
     Message pullResponseMessage)
 {
     var pagedSearchResults =
         pullResponseMessage.GetBody<PagedSearchResults>(new SoapXmlSerializer(typeof(PagedSearchResults)));
     if (pagedSearchResults.Items != null)
     {
         var xmlNodes = (XmlNode[])pagedSearchResults.Items;
         var resources = xmlNodes.Select(BuildResource).ToArray();
         pagedSearchResults.Results.AddRange(resources);
         pagingContext.CurrentIndex += xmlNodes.Length;
     }
     return pagedSearchResults;
 }
开发者ID:sunmorgus,项目名称:ms-idm-net,代码行数:14,代码来源:IdmNetClient.cs

示例15: 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)
        {
            var generator = new NameGenerator(message,
                Connection.ConnectionFactory.ConnectionUri.Path, Connection.ConnectionFactory.ConnectionUri.FileName);

            string sourcePath = new Uri(message.Headers.Action).LocalPath;

            string targetFolder = generator.Folder;
            string targetPath = Path.Combine(targetFolder, generator.FileName);

            if (!Directory.Exists(targetFolder))
                Directory.CreateDirectory(targetFolder);

            Stream outputStream = null;

            switch (Connection.ConnectionFactory.Adapter.OverwriteAction)
            {
                case OverwriteAction.None:
                    outputStream = System.IO.File.Open(targetPath, FileMode.CreateNew);
                    break;
                case OverwriteAction.Replace:
                    outputStream = System.IO.File.Create(targetPath);
                    break;
                case OverwriteAction.Append:
                    outputStream = System.IO.File.OpenWrite(targetPath);
                    break;
            }

            using (outputStream)
            {
                var inputStream = message.GetBody<Stream>();
                inputStream.CopyTo(outputStream);

                return Message.CreateMessage(MessageVersion.Default, string.Empty);
            }
        }
开发者ID:mi-tettamanti,项目名称:mercury-contrib-adapters,代码行数:40,代码来源:FileAdapterOutboundHandler.cs


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