Click here to Skip to main content
15,918,516 members
Please Sign up or sign in to vote.
4.50/5 (2 votes)
See more:
I have created restful service with ItemTrackingDetailsRequest as input for GetItemTrackingDetails.

<ServiceContract()> _
Public Interface IItemTrackerService
    <OperationContract()> _
    <WebInvoke(Method:="POST", RequestFormat:=WebMessageFormat.Xml, ResponseFormat:=WebMessageFormat.Xml, BodyStyle:=WebMessageBodyStyle.Bare, UriTemplate:="GetItemTrackingDetails")> _
    Function GetItemTrackingDetails(ByVal rData As ItemTrackingDetailsRequest) As ItemTrackingDetailsResponse
End Interface
<DataContract(Namespace:="")> _
Public Class ItemTrackingDetailsRequest
    Public ItemTrackingNumbers As New ItemTrackingNumbers()
End Class
<DataContract()> _
Public Class ItemTrackingNumbers
'If I declare TrackingNumber as normal string, it will not throw bad request. But the purpose of reading the Tracking Numbers is not served. 
    <DataMember()> _
    Public TrackingNumber() As String
End ClassThe input xml is as follows

<ItemTrackingDetailsRequest xmlns="">

How can I read the all the TrackingNumbers to an array from ItemTrackingDetailsRequest class object in the method GetItemTrackingDetails. When I change the TrackingNumber in class from string to string array, it throws bad request from client. Just I want to read all the TrackingNumbers from the xml in to the ItemTrackingDetailsRequest object like this.
Public Function GetItemTrackingDetails(ByVal request As ItemTrackingDetailsRequest) As ItemTrackingDetailsResponse Implements IItemTrackerService.GetItemTrackingDetails
    'Calling like request.ItemTrackingNumbers.TrackingNumber(0).ToString() is not working and throwing Bad Request from Client    
Dim strTrackingNumber1 = request.ItemTrackingNumbers.TrackingNumber(0).ToString()
Dim strTrackingNumber2 = request.ItemTrackingNumbers.TrackingNumber(1).ToString()
End Function

The below is the client calling code
Const url As String = "http://localhost:8003/ItemTracker/ItemTrackerService.svc/GetItemTrackingDetails"
req = DirectCast(WebRequest.Create(url), HttpWebRequest)
req.Method = "POST"
req.ContentType = "application/xml; charset=utf-8"
req.Timeout = 300000
req.KeepAlive = False
req.Headers.Add("SOAPAction", url)
Dim xmlDoc = New XmlDocument With {.XmlResolver = Nothing}
Dim sXml As String = xmlDoc.InnerXml
req.ContentLength = sXml.Length
Dim sw = New StreamWriter(req.GetRequestStream())
res = DirectCast(req.GetResponse(), HttpWebResponse)
Dim responseStream As Stream = res.GetResponseStream()
Dim streamReader = New StreamReader(responseStream)
'Read the response into an xml document
Dim soapResonseXmlDocument = New XmlDocument()
soapResonseXmlDocument.Save(AppDomain.CurrentDomain.BaseDirectory & "ItemTrackingDetailsRes.xml")
Updated 8-Jun-12 15:10pm

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900