• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1057
  • Last Modified:

How to generate multiple xml nodes in my WebMethod response

I want to generate multiple xml nodes in my WebMethod response.

I don't know how to write the WebMethod() to generate this...
<myResponse>
<Price>34.5</Price>
<DateTime>8/17/2012</DateTime>
<misc1>aaa</misc1>
<misc2>bbb</misc2>
<misc3>ccc</misc3>
</myResponse>


reference my recent SOAP question:
http://www.experts-exchange.com/Programming/Languages/.NET/ASP.NET/Q_27832901.html

' Request
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
  <soap:Body>
    <GetStockPrice xmlns="http://www.domaintest.org/">
      <StockName>string</StockName>
    </GetStockPrice>
  </soap:Body>
</soap:Envelope>

' Response
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
  <soap:Body>
    <GetStockPriceResponse xmlns="http://www.domaintest.org/">
      <GetStockPriceResult>
           <myResponse>
                 <Price>string</Price>
                 <DateTime>datetime</DateTime>
                 <misc1>string</misc1>
                 <misc2>string</misc2>
                 <misc3>string</misc3>
         </myResponse>
      </GetStockPriceResult>
    </GetStockPriceResponse>
  </soap:Body>
</soap:Envelope>
0
MikeCombe
Asked:
MikeCombe
  • 3
  • 2
1 Solution
 
Rose BabuSenior Team ManagerCommented:
Hi,

http://www.experts-exchange.com/Programming/Languages/.NET/ASP.NET/Q_27832901.html#a38305535

by refereing the above solution, add the additional fields in the GetStockPriceDetails class

and set the additional values in the response object as mentione in below sample code.

Class GetStockPriceDetails
	Private PriceField As String
	Private DateTimeField As String
	Private misc1Field As String
	Private misc2Field As String
	Private misc3Field As String

	Public Property Price() As String
		Get
			Return PriceField
		End Get
		Set(ByVal value As String)
			PriceField = value
		End Set
	End Property

	Public Property DateTime() As String
		Get
			Return DateTimeField
		End Get
		Set(ByVal value As String)
			DateTimeField = value
		End Set
	End Property

	Public Property misc1() As String
		Get
			Return misc1Field
		End Get
		Set(ByVal value As String)
			misc1Field = value
		End Set
	End Property

	Public Property misc2() As String
		Get
			Return misc2Field
		End Get
		Set(ByVal value As String)
			misc2Field = value
		End Set
	End Property

	Public Property misc3() As String
		Get
			Return misc3Field
		End Get
		Set(ByVal value As String)
			misc3Field = value
		End Set
	End Property

End Class

<WebMethod()> _
Public Function GetStockPrice(ByVal StockName As String) As GetStockPriceDetails
	Dim resp As New GetStockPriceDetails
	resp.Price = "34.5"
	resp.DateTime = "8/17/2012"
	resp.misc1 = "aaa"
	resp.misc2 = "bbb"
	resp.misc3 = "ccc"
	Return resp
End Function

Open in new window

0
 
MikeCombeAuthor Commented:
perfect !
thanks again
0
 
MikeCombeAuthor Commented:
A follow up question...

Looking at:
<soap:Body>
    <GetStockPriceResponse xmlns="https://somewherecom/SoapTest/">
      <GetStockPriceResult>
        <Price>string</Price>
        <DateTime>string</DateTime>
        <misc1>string</misc1>
        <misc2>string</misc2>
        <misc3>string</misc3>
      </GetStockPriceResult>
    </GetStockPriceResponse>
  </soap:Body>

How is the node  "<GetStockPriceResult>" set (or created) ?
0
 
Rose BabuSenior Team ManagerCommented:
<GetStockPriceResult> is created by webservice program.
0
 
MikeCombeAuthor Commented:
ok....yes. It's generated by the name of the Function:
Public Function GetStockPrice(ByVal StockName As String) As GetStockPriceDetails

which generates
<GetStockPriceResult>

Thanks !
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now