Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Sending xml stream data

Status
Not open for further replies.

Dashley

Programmer
Dec 5, 2002
925
US
I'm using the code below to send data up from a PDA to a website. There are options that a client can choose
like " > .05 % " or " < .05% ". These optiones wind up in comments that have to go up as text.


The problem is that the less than or greater than signs when read into the xml brake the tags in the xml reader later on. Using a replace command would work except it replaces the xml tags and it dosent seem to be the best option.

Any Ideas?


Thansk






Code:
Dim Sw1 As New StringWriter
Dim xmlWriter1 As New XmlTextWriter(Sw1)

' fill my Data reader

xmlWriter1.WriteStartElement("resulstin")

Do While Dreader.Read()
                xmlWriter1.WriteStartElement("res")
                xmlWriter1.WriteElementString("resultid", Dreader.GetInt32(0))
                DBResultID = Dreader("resultid")
                xmlWriter1.WriteElementString("scheduleentryid", Dreader.GetInt32(1))

loop


xmlWriter1.WriteEndElement()

mystring = Sw1.ToString

myresult = GetWebPageResult(mystring)
 
why don't you HTMLEncode it on the PDA side and HTMLDecode on the website side?
 
rick

hi.

can I just send the dataset to the website?


-dan
 
Rick,

The code for the GetWebPage Result is below. This sending a dataset to the webservice intrests me. Would'nt happen to have a link I can go research? I'm headed to the help files right now.

thanks

-dan



Code:
Public Function GetWebPageResult( _
             ByVal urlrequest As String, _
             Optional ByVal bAllowAutoRedirect As Boolean = True, _
             Optional ByVal iTimeout As Integer = System.Threading.Timeout.Infinite _
         ) As String
        Dim webRequest As System.Net.HttpWebRequest
        Dim webResponse As System.Net.HttpWebResponse
        Try
          

            webRequest = CType(System.Net.WebRequest.Create(urlrequest), System.Net.HttpWebRequest)
            webRequest.AllowAutoRedirect = bAllowAutoRedirect
            'webRequest.MaximumAutomaticRedirections = 50
            webRequest.Timeout = iTimeout
            webResponse = CType(webRequest.GetResponse(), System.Net.HttpWebResponse)


            Try
                'webResponse = CType(webRequest.GetResponse(), System.Net.HttpWebResponse)
                Select Case (webResponse.StatusCode)
                    Case System.Net.HttpStatusCode.OK

                        Dim responseStream As System.IO.Stream = _
                            webResponse.GetResponseStream()
                        Dim responseEncoding As System.Text.Encoding = _
                            System.Text.Encoding.UTF8

                        Dim responseReader As New StreamReader(responseStream, responseEncoding)
                        Dim responseContent As String = _
                            responseReader.ReadToEnd()
                        Return responseContent

                    Case System.Net.HttpStatusCode.Redirect, System.Net.HttpStatusCode.MovedPermanently
                        Throw New System.Exception(String.Format( _
                            "Unable to read response content.  URL has moved. StatusCode={0}.", _
                            webResponse.StatusCode))
                    Case System.Net.HttpStatusCode.NotFound
                        Throw New System.Exception(String.Format( _
                            "Unable to read response content. URL not found. StatusCode={0}.", _
                            webResponse.StatusCode))
                    Case Else
                        Throw New System.Exception(String.Format( _
                            "Unable to read response content. StatusCode={0}.", _
                            webResponse.StatusCode))
                End Select

            Catch we As System.Net.WebException
                'If (we.Status = Net.WebExceptionStatus.Timeout) Then
                '    Return False
                'End If
                Throw New System.Exception( _
                    "Unable to execute URL.", _
                    we)
            Finally
                If (Not IsNothing(webResponse)) Then
                    webResponse.Close()
                End If
            End Try
        Catch e As System.Exception
            Throw New System.Exception( _
                "Unable to execute URL.", _
                e)
        End Try



    End Function
 
I'm not sure I follow what you are doing specificly. Are you trying to pass XML in the URL? Like:


If so, then you'll have to do some more work. If you have a WebService running on the web server, you can pass it a dataset with no extra work though. If you are trying to get the XML as a string to pass on through the URL though, you can do this:

Code:
    Dim ds As New DataSet

    'This block of code is just populated the dataset
    'for demo purposes
    '***********************************************
    ds.Tables.Add()
    ds.Tables(0).Columns.Add("ID", GetType(Integer))
    ds.Tables(0).Columns.Add("Value", GetType(String))
    Dim dr As DataRow
    dr = ds.Tables(0).NewRow
    dr("ID") = 1
    dr("Value") = "< 5%"
    ds.Tables(0).Rows.Add(dr)

    dr = ds.Tables(0).NewRow
    dr("ID") = 2
    dr("Value") = "> 5%"
    ds.Tables(0).Rows.Add(dr)

    dr = ds.Tables(0).NewRow
    dr("ID") = 3
    dr("Value") = "& many more"
    ds.Tables(0).Rows.Add(dr)
    '***********************************************
  
    'This is where we convert the DataSet into a string

    Dim w As New System.IO.StringWriter
    Dim ms As New Xml.XmlTextWriter(w)
    ds.WriteXml(ms)
    MsgBox(w.ToString)
    
    'w.ToString will return a web friendly (> will be &gt;) string.

-Rick

VB.Net Forum forum796 forum855 ASP.NET Forum
[monkey]I believe in killer coding ninja monkeys.[monkey]
 
Rick,

Hi.

I'm just guessing but I think the best practice would be
passing the dataset to the/a webservice.

I could pass the string in the URL like you have shown me.

Im kind of doing that right now using (My frst code above). I build the xml and then write it to a string via a string writer and then I send it up via the URL.

I want to do whatever is best.

 
Ok I have the string writting correctly and the XML. My probem is I can't send it throgh the URL all at once because its to long.

Is there another option for sending such a long string.
I've been looking but with no luck
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top