Click here to Skip to main content
Rate this: bad
Please Sign up or sign in to vote.
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")
Posted 8-Jun-12 4:43am
Edited 8-Jun-12 15:10pm

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

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 505
1 OriginalGriff 248
2 ChintanShukla 185
3 Richard Deeming 175
4 Bhavik_Patel 170
0 Sergey Alexandrovich Kryukov 8,688
1 OriginalGriff 7,237
2 CPallini 2,598
3 Richard MacCutchan 2,080
4 Abhinav S 1,888

Advertise | Privacy | Mobile
Web03 | 2.8.140827.1 | Last Updated 8 Jun 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100