Product prod = new Product("Widget", 1.5M); string accessKeyId = ConfigurationSettings.AppSettings["AmazonAccessKeyID"]; string secretAccessKey = ConfigurationSettings.AppSettings["AmazonSecretAccessKey"]; AmazonSQS service = new AmazonSQSClient(accessKeyId, secretAccessKey); SendMessageRequest request = new SendMessageRequest(); request.MessageBody = prod.ToXml(); request.QueueName = "TestQueue"; SendMessageResponse response = service.SendMessage(request); if (response.IsSetSendMessageResult()) { Console.WriteLine("Send Message Response: "); SendMessageResult sendMessageResult = response.SendMessageResult; if (sendMessageResult.IsSetMessageId()) { Console.WriteLine(String.Format("MessageId {0}", sendMessageResult.MessageId)); } if (sendMessageResult.IsSetMD5OfMessageBody()) { Console.WriteLine(String.Format("MD5OfMessageBody: {0}", sendMessageResult.MD5OfMessageBody)); } } |
Product prod = null; string accessKeyId = ConfigurationSettings.AppSettings["AmazonAccessKeyID"]; string secretAccessKey = ConfigurationSettings.AppSettings["AmazonSecretAccessKey"]; AmazonSQS service = new AmazonSQSClient(accessKeyId, secretAccessKey); ReceiveMessageRequest request = new ReceiveMessageRequest(); request.QueueName = "TestQueue"; ReceiveMessageResponse response = service.ReceiveMessage(request); if (response.IsSetReceiveMessageResult()) { Console.WriteLine("Receive Message Result:"); ReceiveMessageResult receiveMessageResult = response.ReceiveMessageResult; List<Message> messageList = receiveMessageResult.Message; foreach (Message message in messageList) { if (message.IsSetMessageId()) { Console.WriteLine(String.Format("MessageId: {0}", message.MessageId)); } if (message.IsSetBody()) { Console.WriteLine(string.Format("Body: {0}", message.Body)); String xml = message.Body; StringReader sr = new StringReader(xml); XmlSerializer serializer = new XmlSerializer(typeof(Product)); prod = (Product) serializer.Deserialize(sr); Console.WriteLine(string.Format("Id: {0}", prod.Id)); Console.WriteLine(string.Format("Name: {0}", prod.ProductName)); Console.WriteLine(string.Format("Price: {0}", prod.ProductPrice)); } } } |
<?xml version="1.0" encoding="utf-8"?> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"> <xs:element name="PurchaseOrder"> <xs:complexType> <xs:sequence> <xs:element name="Id" type="xs:string" minOccurs="0" /> <xs:element name="OrderDate" type="xs:string" minOccurs="0" /> <xs:element name="Company" minOccurs="0" maxOccurs="unbounded"> <xs:complexType> <xs:sequence> <xs:element name="CompanyName" type="xs:string" minOccurs="0" /> <xs:element name="StreetAddress" type="xs:string" minOccurs="0" /> <xs:element name="City" type="xs:string" minOccurs="0" /> <xs:element name="State" type="xs:string" minOccurs="0" /> <xs:element name="ZipCode" type="xs:string" minOccurs="0" /> </xs:sequence> </xs:complexType> </xs:element> <xs:element name="Vendor" minOccurs="0" maxOccurs="unbounded"> <xs:complexType> <xs:sequence> <xs:element name="CompanyName" type="xs:string" minOccurs="0" /> <xs:element name="StreetAddress" type="xs:string" minOccurs="0" /> <xs:element name="City" type="xs:string" minOccurs="0" /> <xs:element name="State" type="xs:string" minOccurs="0" /> <xs:element name="ZipCode" type="xs:string" minOccurs="0" /> </xs:sequence> </xs:complexType> </xs:element> <xs:element name="Items" minOccurs="0" maxOccurs="unbounded"> <xs:complexType> <xs:sequence> <xs:element name="Item" minOccurs="0" maxOccurs="unbounded"> <xs:complexType> <xs:attribute name="Id" type="xs:string" /> <xs:attribute name="Name" type="xs:string" /> <xs:attribute name="Quantity" type="xs:string" /> </xs:complexType> </xs:element> </xs:sequence> </xs:complexType> </xs:element> </xs:sequence> </xs:complexType> </xs:element> </xs:schema> |
关键元素
|
描述
|
Id
|
包含 Purchase Order 的唯一标识符的字符串
|
OrderDate
|
包含 Purchase Order 日期的字符串
|
Company
|
包含分销商的关键地址信息,包括公司名称、街道地址、城市、州和邮政编码
|
Vendor
|
包含制造商的关键地址信息,包括公司名称、街道地址、城市、州和邮政编码
|
Items
|
包含订购商品的所有信息,包括商品 ID、商品名称和数量
|
<?xml version="1.0" encoding="utf-8"?> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"> <xs:element name="OrderSummary"> <xs:complexType> <xs:sequence> <xs:element name="OrderId" type="xs:string" minOccurs="0" /> <xs:element name="ReferenceId" type="xs:string" minOccurs="0" /> <xs:element name="OrderDate" type="xs:string" minOccurs="0" /> <xs:element name="CompanyAddress" minOccurs="0" maxOccurs="unbounded"> <xs:complexType> <xs:sequence> <xs:element name="CompanyName" type="xs:string" minOccurs="0" /> <xs:element name="StreetAddress" type="xs:string" minOccurs="0" /> <xs:element name="City" type="xs:string" minOccurs="0" /> <xs:element name="State" type="xs:string" minOccurs="0" /> <xs:element name="ZipCode" type="xs:string" minOccurs="0" /> </xs:sequence> </xs:complexType> </xs:element> <xs:element name="CustomerAddress" minOccurs="0" maxOccurs="unbounded"> <xs:complexType> <xs:sequence> <xs:element name="CompanyName" type="xs:string" minOccurs="0" /> <xs:element name="StreetAddress" type="xs:string" minOccurs="0" /> <xs:element name="City" type="xs:string" minOccurs="0" /> <xs:element name="State" type="xs:string" minOccurs="0" /> <xs:element name="ZipCode" type="xs:string" minOccurs="0" /> </xs:sequence> </xs:complexType> </xs:element> <xs:element name="Items" minOccurs="0" maxOccurs="unbounded"> <xs:complexType> <xs:sequence> <xs:element name="Item" minOccurs="0" maxOccurs="unbounded"> <xs:complexType> <xs:attribute name="ItemId" type="xs:string" /> <xs:attribute name="ItemName" type="xs:string" /> <xs:attribute name="Quantity" type="xs:string" /> </xs:complexType> </xs:element> </xs:sequence> </xs:complexType> </xs:element> </xs:sequence> </xs:complexType> </xs:element> </xs:schema> |
Id
|
包含 Order Summary 的唯一标识符的字符串
|
ReferenceId
|
包含初始 Purchase Order 的 ID 的字符串
|
OrderDate
|
包含 Order Summary 日期的字符串
|
CustomerAddress
|
包含分销商的关键地址信息,包括公司名称、街道地址、城市、州和邮政编码
|
VendorAddress
|
包含制造商的关键地址信息,包括公司名称、街道地址、城市、州和邮政编码
|
Items
|
包含订购商品的所有信息,包括商品 ID、商品名称和数量
|
(责任编辑:)
作为一名运维工程师,工作中最大的希望就是自己运维的网站能够稳定高效运行,但理想很...[详细]
电脑高手们都会尽可能地寻找各种快捷高效的操作方式,譬如很多快速启动类的工具(如Exe...[详细]
全闪存数据中心是个未来概念,同样还有不少方法实现数据中心内服务器或基于阵列的闪存...[详细]
手机九宫格解锁到底安全不?九宫格能画出多少图案啊?我自己设置的九宫格总是被同学分...[详细]
一名黑客生成加密程序的作者竟然没有实现其核心的功能:加密! 这位ID为NinjaDoge24(...[详细]