2310 b xd

452 views
414 views

Published on

0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
452
On SlideShare
0
From Embeds
0
Number of Embeds
2
Actions
Shares
0
Downloads
3
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

2310 b xd

  1. 1. Appendix D: XML Web Service Responses
  2. 2. Lesson: XML Web Service Responses <ul><li>XML Web Service Responses </li></ul><ul><li>Default Formatted XML Web Service Responses </li></ul><ul><li>Reshaping XML Web Service Responses </li></ul><ul><li>Demonstration: Reshaping XML Web Service Responses </li></ul>
  3. 3. XML Web Service Responses <ul><li>Web services respond to direct HTTP-GET calls with simple XML documents </li></ul><ul><li>Web services respond to application-to-application calls with SOAP envelopes </li></ul><ul><ul><li>Envelope definition </li></ul></ul><ul><ul><li>Encoding rules </li></ul></ul><ul><ul><li>RPC representation </li></ul></ul><ul><ul><li>Protocol bindings </li></ul></ul>
  4. 4. Default Formatted XML Web Service Responses <?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot; ?> <ArrayOfContact> <Contact>   <name>Janet</name>   <address>Seattle, WA</address>   </Contact> <Contact>   <name>Joe</name>   <address>Attleboro, MA</address>   </Contact> </ArrayOfContact> <ul><li>XML Web service code for an array </li></ul><ul><li>Resulting XML data </li></ul>Public Structure Contact Public name As String Public address As String End Structure <WebMethod()>Public Function _ GetContacts() As Contact() Dim x(1) As Contact x(0).name = &quot;Janet&quot; x(0).address = &quot;Seattle, WA&quot; x(1).name = &quot;Joe&quot; x(1).address = &quot;Attleboro, MA&quot; Return x End Function public struct Contact { public string name; public string address; } [WebMethod()]public Contact[] GetContacts() { Contact[] x; x = new Contact[2]; x[0].name = &quot;Janet&quot;; x[0].address = &quot;Seattle, WA&quot;; x[1].name = &quot;Joe&quot;; x[1].address = &quot;Attleboro, MA&quot;; return x; }
  5. 5. Reshaping XML Web Service Responses <ul><li>XML Web service revised code </li></ul><ul><li>Resulting XML response </li></ul><XmlType(&quot;MyContact&quot;)>Public Structure Contact <XmlAttributeAttribute(&quot;ContactName&quot;)> _ Public name As String <XmlAttributeAttribute(&quot;ContactAddress&quot;)> _ Public address As String End Structure <?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?> <ArrayOfMyContact>   <MyContact ContactName=&quot;Janet&quot; ContactAddress=&quot;Seattle, WA&quot; />   <MyContact ContactName =&quot;Joe&quot; ContactAddress=&quot;Attleboro, MA&quot; /> </ArrayOfMyContact> [XmlType(&quot;MyContact&quot;)]public struct Contact{ [XmlAttributeAttribute(&quot;ContactName&quot;)] public string name; [XmlAttributeAttribute(&quot;ContactAddress&quot;)] public String address; }
  6. 6. Demonstration: Reshaping XML Web Service Responses <ul><li>Add a Web method that returns a list of contacts (structure) </li></ul><ul><li>Reshape the returned XML </li></ul>

×