2310 b xd
-
Upload
krazy-koder -
Category
Documents
-
view
582 -
download
1
description
Transcript of 2310 b xd
![Page 1: 2310 b xd](https://reader036.fdocuments.in/reader036/viewer/2022082623/5472c170b4af9f980a8b4fd1/html5/thumbnails/1.jpg)
Appendix D:XML Web Service
Responses
![Page 2: 2310 b xd](https://reader036.fdocuments.in/reader036/viewer/2022082623/5472c170b4af9f980a8b4fd1/html5/thumbnails/2.jpg)
Lesson: XML Web Service Responses
XML Web Service Responses
Default Formatted XML Web Service Responses
Reshaping XML Web Service Responses
Demonstration: Reshaping XML Web Service Responses
![Page 3: 2310 b xd](https://reader036.fdocuments.in/reader036/viewer/2022082623/5472c170b4af9f980a8b4fd1/html5/thumbnails/3.jpg)
XML Web Service Responses
Web services respond to direct HTTP-GET calls with simple XML documents
Web services respond to application-to-application calls with SOAP envelopes
Envelope definition
Encoding rules
RPC representation
Protocol bindings
![Page 4: 2310 b xd](https://reader036.fdocuments.in/reader036/viewer/2022082623/5472c170b4af9f980a8b4fd1/html5/thumbnails/4.jpg)
<?xml version="1.0" encoding="utf-8" ?> <ArrayOfContact> <Contact> <name>Janet</name> <address>Seattle, WA</address> </Contact> <Contact> <name>Joe</name> <address>Attleboro, MA</address> </Contact></ArrayOfContact>
<?xml version="1.0" encoding="utf-8" ?> <ArrayOfContact> <Contact> <name>Janet</name> <address>Seattle, WA</address> </Contact> <Contact> <name>Joe</name> <address>Attleboro, MA</address> </Contact></ArrayOfContact>
Default Formatted XML Web Service Responses
XML Web service code for an array
Resulting XML dataPublic Structure Contact Public name As String Public address As StringEnd Structure
<WebMethod()>Public Function _ GetContacts() As Contact()
Dim x(1) As Contact x(0).name = "Janet" x(0).address = "Seattle, WA" x(1).name = "Joe" x(1).address = "Attleboro, MA" Return xEnd Function
Public Structure Contact Public name As String Public address As StringEnd Structure
<WebMethod()>Public Function _ GetContacts() As Contact()
Dim x(1) As Contact x(0).name = "Janet" x(0).address = "Seattle, WA" x(1).name = "Joe" x(1).address = "Attleboro, MA" Return xEnd Function
public struct Contact{ public string name; public string address;}
[WebMethod()]public Contact[] GetContacts()
{ Contact[] x; x = new Contact[2]; x[0].name = "Janet"; x[0].address = "Seattle, WA"; x[1].name = "Joe"; x[1].address = "Attleboro, MA"; return x;}
public struct Contact{ public string name; public string address;}
[WebMethod()]public Contact[] GetContacts()
{ Contact[] x; x = new Contact[2]; x[0].name = "Janet"; x[0].address = "Seattle, WA"; x[1].name = "Joe"; x[1].address = "Attleboro, MA"; return x;}
![Page 5: 2310 b xd](https://reader036.fdocuments.in/reader036/viewer/2022082623/5472c170b4af9f980a8b4fd1/html5/thumbnails/5.jpg)
Reshaping XML Web Service Responses
XML Web service revised code
Resulting XML response
<XmlType("MyContact")>Public Structure Contact <XmlAttributeAttribute("ContactName")> _
Public name As String <XmlAttributeAttribute("ContactAddress")> _
Public address As StringEnd Structure
<XmlType("MyContact")>Public Structure Contact <XmlAttributeAttribute("ContactName")> _
Public name As String <XmlAttributeAttribute("ContactAddress")> _
Public address As StringEnd Structure
<?xml version="1.0" encoding="utf-8"?><ArrayOfMyContact> <MyContact ContactName="Janet"
ContactAddress="Seattle, WA" /> <MyContact ContactName ="Joe"
ContactAddress="Attleboro, MA" /> </ArrayOfMyContact>
<?xml version="1.0" encoding="utf-8"?><ArrayOfMyContact> <MyContact ContactName="Janet"
ContactAddress="Seattle, WA" /> <MyContact ContactName ="Joe"
ContactAddress="Attleboro, MA" /> </ArrayOfMyContact>
[XmlType("MyContact")]public struct Contact{ [XmlAttributeAttribute("ContactName")] public string name; [XmlAttributeAttribute("ContactAddress")]
public String address;}
[XmlType("MyContact")]public struct Contact{ [XmlAttributeAttribute("ContactName")] public string name; [XmlAttributeAttribute("ContactAddress")]
public String address;}
![Page 6: 2310 b xd](https://reader036.fdocuments.in/reader036/viewer/2022082623/5472c170b4af9f980a8b4fd1/html5/thumbnails/6.jpg)
Demonstration: Reshaping XML Web Service Responses
Add a Web method that returns a list of contacts (structure)
Reshape the returned XML