loading xmldocument with httpwebrequest object?

D

deepak

Hi ALL,

Is it possible to load a xmldocument(say xmldoc) with a httpwebrequest object?

Thanks,
Deepak
 
M

Martin Honnen

deepak said:
Is it possible to load a xmldocument(say xmldoc) with a httpwebrequest object?

You can load the response stream e.g.
XmlDocument xmlDoc = new XmlDocument();
HttpWebRequest request =
(HttpWebRequest)WebRequest.Create("http://example.com/whatever.aspx");
// set request properties here as needed
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
xmlDoc.Load(response.GetResponseStream());
 
D

deepak

Hi Martin,

yes its loading now but i want to post the xml of this xmldocument back to
html page through 'Response' Object(httpResponse) to the page ...Is it
possible?i m doing somethign like this...

rsp = req.GetResponse()

Dim xmlDocResponse As New XmlDocument
xmlDocResponse.Load(rsp.GetResponseStream())


Response.ContentType = "text/xml"
Response.Charset = "utf-8"

' Dim a = CreateObject("Microsoft.XMLDOM")
' Call a.load(rsp.GetResponseStream())

' Response.ContentType = "text/xml"
' Response.Charset = "utf-8"


Response.Write(a.xml)
Response.End()

but this is givign error,do u have any suggestions...?
- Deepak
 
M

Martin Honnen

deepak said:
yes its loading now but i want to post the xml of this xmldocument back to
html page through 'Response' Object(httpResponse) to the page ...Is it
possible?i m doing somethign like this...

rsp = req.GetResponse()

Dim xmlDocResponse As New XmlDocument
xmlDocResponse.Load(rsp.GetResponseStream())


Response.ContentType = "text/xml"
Response.Charset = "utf-8"

xmlDocResponse.Save(Response.OutputStream)
 
D

deepak

Hi Martin,
Tons of thanks again....u r really a man..i started liking you and your
strong technical skill with fast reponse always...:)

- Deepak
 
D

deepak

Hi Martin,

In this sucessfull outgoing message, i have many tags like engineer
name,address etc.Also different type of date tags and their values(means
innertext and innerxml) like EarlyStart,DesiredDueDate,DueDate,TimeCreated
etc as shown below:

<SXPTaskUpdateOrAddResult>
<ReturnCode>Success</ReturnCode>
<Task>
<Key>37820794</Key>
<Revision>10</Revision>
<Stamp>
<CreatedBy>India_Bharti</CreatedBy>
<TimeCreated>2008-02-14T12:44:39</TimeCreated>
<CreatingProcess>0</CreatingProcess>
<ModifiedBy>NT AUTHORITY\NETWORK SERVICE</ModifiedBy>
<TimeModified>2008-02-14T16:39:19</TimeModified>
<ModifyingProcess>0</ModifyingProcess>
</Stamp>
<CallID>KPN-NL_Deepak_0214_5</CallID>
<Number>0</Number>
<EarlyStart>2008-02-14T14:30:00</EarlyStart>
<DueDate>2008-02-14T15:44:00</DueDate>
<LateStart>1899-12-30T00:00:00</LateStart>
<Priority>1</Priority>
<Status Key="124127236">Unassigned</Status>
<Customer>KPN-NL</Customer>
<Calendar Key="50432000">NL Service Calendar (24x7)</Calendar>
<Region Key="124020736">NL</Region>
<District Key="258627584">NL KPN</District>
<Postcode>
</Postcode>
<PreferredEngineers>
</PreferredEngineers>
<ContractType Key="-1">
</ContractType>
<OpenDate>1899-12-30T00:00:00</OpenDate>
<ContactDate>1899-12-30T00:00:00</ContactDate>
<ConfirmationDate>1899-12-30T00:00:00</ConfirmationDate>
<TaskType Key="124786688">Corrective</TaskType>
<Duration>5400</Duration>
<RequiredEngineers>
</RequiredEngineers>
<NumberOfRequiredEngineers>1</NumberOfRequiredEngineers>
<RequiredSkills1>
<TaskRequiredSkill1>
<Key Key="125063170">Wireless Access _ 2G _ Nokia</Key>
<SkillLevel>3</SkillLevel>
</TaskRequiredSkill1>
<TaskRequiredSkill1>
<Key Key="125063168">Wireless Access _2G</Key>
<SkillLevel>3</SkillLevel>
</TaskRequiredSkill1>
</RequiredSkills1>
<RequiredSkills2>
</RequiredSkills2>
<EngineerType Key="-1">
</EngineerType>
<RequiredEngineerTools>
</RequiredEngineerTools>
<Critical>0</Critical>
<TimeDependencies>
</TimeDependencies>
<EngineerDependencies>
</EngineerDependencies>
<AppointmentStart>1899-12-30T00:00:00</AppointmentStart>
<AppointmentFinish>1899-12-30T00:00:00</AppointmentFinish>
<ContactName>Fredrik Viberg</ContactName>
<ContactPhoneNumber>+46 730 51 38 96</ContactPhoneNumber>

<BinaryData>LAAAAAAAPPPPPPPPPPPPPPPPOGAAAAAACAAAAAAACAAAAAAAFGAAAAAAAAAACAAFEHHAFGAAAAAAAAAADAAAAAAACAAAAAAAFGAAAAAAAAAAAAAFEHHAFGAAAAAAAAAADAAAAAAAPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPP</BinaryData>
<Latitude>48019769</Latitude>
<Longitude>3338705</Longitude>
<GISDataSource>0</GISDataSource>
<Street>
</Street>
<City>
</City>
<State>
</State>
<TaskStatusContext>0</TaskStatusContext>
<IsCrewTask>0</IsCrewTask>
<CountryID Key="126105600">Netherlands</CountryID>
<EngineerRequirements>
</EngineerRequirements>
<IsScheduled>0</IsScheduled>
<CustomerEmail>
</CustomerEmail>
<ExcludedEngineers>
</ExcludedEngineers>
<NOCRefID>Deepak_0214_5</NOCRefID>
<Title>The work order title</Title>
<ServiceArea2 Key="126629888">NL Region 1</ServiceArea2>
<ServiceArea1 Key="126756864">NL Field Operations</ServiceArea1>
<SRO Key="126885888">ENN</SRO>
<MarketUnit Key="127016960">NE</MarketUnit>
<DescriptionLog>The description of the problem
India_Bharti / 2/14/2008 12:44:00 PM
The description of the problem
India_Bharti / 2/14/2008 12:53:59 PM
The description of the problem
India_Bharti / 2/14/2008 1:09:00 PM
The description of the problem
India_Bharti / 2/14/2008 1:12:59 PM
The description of the problem
India_Bharti / 2/14/2008 1:35:59 PM
The description of the problem
India_Bharti / 2/14/2008 1:36:00 PM
last comment only
ER_Kista / 2/14/2008 1:44:00 PM
last comment only
ER_Kista / 2/14/2008 4:34:00 PM
last comment only
ER_Kista / 2/14/2008 4:38:00 PM
last comment only
ER_Kista / 2/14/2008 4:38:59 PM
last comment only
ER_Kista / 2/14/2008 5:38:59 PM
</DescriptionLog>
<DesiredDueDate>2008-02-14T14:30:00</DesiredDueDate>
<Site>0637</Site>
<CustomerAddress>Mauritsweg 134</CustomerAddress>
<SolutionReport>
</SolutionReport>
<Attachments>
</Attachments>
<LatestAttachments>
</LatestAttachments>
<WOTimeCreated>2008-02-14T12:44:40</WOTimeCreated>
<NewComment>
</NewComment>
<SiteAddress>BENTINCKSKAMP 14 8191HB WAPENVELD</SiteAddress>
<AutoCreate>1</AutoCreate>
<EstimatedDuration>36000</EstimatedDuration>
<TimeToClose>1899-12-30T00:00:00</TimeToClose>
<CombinedDueDate>2008-02-14T14:30:00</CombinedDueDate>
<Warranty>172800</Warranty>
<DispatchedDate>1899-12-30T00:00:00</DispatchedDate>
<SendSMS>0</SendSMS>
<StatusTimes>
</StatusTimes>
<LastStatusUpdate>2008-02-14T12:44:40</LastStatusUpdate>
<ChangedOn>ER_Kista , 2/14/2008 5:39:33 PM</ChangedOn>
<StatusBeforeClosed Key="-1">
</StatusBeforeClosed>
<SLADuration>10800</SLADuration>
<ClosedNumber>0</ClosedNumber>
<CustomerRefKey Key="125329408">KPN-NL</CustomerRefKey>
<EquipmentType Key="127207424">
<Name>A10</Name>
<Customer Key="125329408">KPN-NL</Customer>
</EquipmentType>
<OptionalDate>1899-12-30T00:00:00</OptionalDate>
<HasPreviousWO>0</HasPreviousWO>
<HasPriorityChanged>0</HasPriorityChanged>
<PriorityTimes>
</PriorityTimes>
<MetricDate>2008-02-14T14:30:00</MetricDate>
<LastPriorityUpdate>2008-02-14T11:44:40</LastPriorityUpdate>
<StatusBeforeChange Key="-1">
</StatusBeforeChange>
<WasBackDated>0</WasBackDated>
<EngineerComment>
</EngineerComment>
<SubType>Not Available</SubType>
</Task>
</SXPTaskUpdateOrAddResult>System.Xml.XmlDocument

Is there any way to convert these date's tag(which are in localtime zone of
the server) to UTC Format before sending it outside to client...?

i have a class which is running fine and can be helpful for you and this
works for UTC->Local time zone(means server time zone or u can say to local
machien time zone)


Imports Microsoft.Win32
Imports System.Runtime.InteropServices

Public Class timezone_converter
Private Structure TZI
Dim bias As Integer
Dim standardBias As Integer
Dim daylightBias As Integer
Dim standardDate As SYSTEMTIME
Dim daylightDate As SYSTEMTIME
End Structure

Public Structure TIME_ZONE_INFORMATION
Dim Bias As Integer
<VBFixedArray(32)> Dim StandardName() As Short
Dim StandardDate As SYSTEMTIME
Dim StandardBias As Integer
<VBFixedArray(32)> Dim DaylightName() As Short
Dim DaylightDate As SYSTEMTIME
Dim DaylightBias As Integer

Public Sub Initialize()
ReDim StandardName(32)
ReDim DaylightName(32)
End Sub
End Structure
Public Structure SYSTEMTIME
Dim wYear As Integer
Dim wMonth As Integer
Dim wDayOfWeek As Integer
Dim wDay As Integer
Dim wHour As Integer
Dim wMinute As Integer
Dim wSecond As Integer
Dim wMilliseconds As Integer
End Structure

Public Function UTCtoLocal(ByVal serverdate As DateTime, ByVal tzone As
String) As DateTime
Dim timezoneinfo As TIME_ZONE_INFORMATION
timezoneinfo.Initialize()
Dim servertime As SYSTEMTIME
Dim serverfiletime As New FILETIME
Dim Localfiletime As New FILETIME
Dim Localtime As SYSTEMTIME
Dim custTZI As TZI
Dim strTZI() As Byte
Dim temp1 As Long
Dim temp2 As Integer


Dim strPath As String = "Software\Microsoft\Windows
NT\CurrentVersion\Time Zones\" & tzone
Dim oReg As RegistryKey = Registry.LocalMachine.OpenSubKey(strPath)
strTZI = oReg.GetValue("TZI")
custTZI = BulidStr(strTZI)

timezoneinfo.Bias = custTZI.bias
timezoneinfo.StandardBias = custTZI.standardBias
timezoneinfo.StandardDate = custTZI.standardDate
timezoneinfo.DaylightBias = custTZI.daylightBias
timezoneinfo.DaylightDate = custTZI.daylightDate

temp1 = serverdate.Ticks

serverfiletime.dwHighDateTime = (temp1 >> 32)
temp2 = temp1 And &HFFFFFFFFL
serverfiletime.dwLowDateTime = Convert.ToInt32(temp2.ToString)

'FileTimeToSystemTime which will convert a file time to system time
format.
FileTimeToSystemTime(serverfiletime, servertime)
' TzSpecificLocalTimeToSystemTime(timezoneinfo, servertime, Localtime)

'SystemTimeToTzSpecificLocalTime window function which takes into
account whether the time to be converted falls in daylight saving time or not.
SystemTimeToTzSpecificLocalTime(timezoneinfo, servertime, Localtime)

'SystemTimeToFileTime window function which converts a system time
to a file time.
SystemTimeToFileTime(Localtime, Localfiletime)

temp1 = Convert.ToInt64(Localfiletime.dwHighDateTime) << 32 Or
Convert.ToInt64(BitConverter.ToUInt32((BitConverter.GetBytes(Localfiletime.dwLowDateTime)), 0))
Dim Localdate As New DateTime(temp1)

Return Localdate

End Function


' Declare Sub TzSpecificLocalTimeToSystemTime Lib "kernel32.dll" (ByRef
lpTimeZone As TIME_ZONE_INFORMATION, ByRef lpLocalTime As SYSTEMTIME, ByRef
lpUniversalTime As SYSTEMTIME)
Declare Sub SystemTimeToFileTime Lib "kernel32.dll" (ByRef lpSystemTime
As SYSTEMTIME, ByRef lpFileTime As FILETIME)
Declare Sub FileTimeToSystemTime Lib "kernel32.dll" (ByRef lpFileTime As
FILETIME, ByRef lpSystemTime As SYSTEMTIME)
Declare Sub SystemTimeToTzSpecificLocalTime Lib "kernel32.dll" (ByRef
lpTimeZone As TIME_ZONE_INFORMATION, ByRef lpUniversalTime As SYSTEMTIME,
ByRef lpLocalTime As SYSTEMTIME)


Private Function BulidStr(ByVal Buff() As Byte) As Object
Dim MyGC As GCHandle = GCHandle.Alloc(Buff, GCHandleType.Pinned)
Dim temp As TZI

Dim Obj As Object = Marshal.PtrToStructure(MyGC.AddrOfPinnedObject,
temp.GetType)
Return Obj
'Free GChandle to avoid memory leaks
MyGC.Free()
End Function

End Class
......................................................................................................................

Kinldy let me know how to covert these outgoign tags related (having
dates(s)) inside them into UTC Format?

I know it may take your valuable time but this is the only way...

- Deepak
 
D

deepak

Hi Martin,

May we have this Algorithm:
1. Find all those tags which have the innertext or you can say innerxml as
in the format of say YYYY-MM-DDTtt:tt (i.e. 2008-02-14T12:44:39)
2. store them in array and pass this array to a function which will convert
them into UTC,Take back array.
3. fit these dates into xml and send the reponse object finally.
Kindly let me know please.

- Deepak
 
D

deepak

Hi Martin,
one more thing,
Note:While sending this message outside,always UTC date pattern will remain
same i.e.

UTC Format : 2008-02-14T12:44:39Z

Note: Z is the last word ,which is not there in below xml and this needs to
be attached once a particular date has been converted to UTC format.

-Deepak
 
A

Anthony Jones

deepak said:
Hi Martin,
Tons of thanks again....u r really a man..i started liking you and your
strong technical skill with fast reponse always...:)


Yeah Martin, you're the man! At this rate you'll have written Deepak's
entire app for him ;)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top