473,396 Members | 1,860 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

XML request and response

I am the beginner in this technology and its been 8 hours straight and i am not able to figure out the issue, the first thing i am not understanding is about first 3 tags,
Expand|Select|Wrap|Line Numbers
  1. soapenv:Envelope
  2. soapenv:Header
  3. soapenv:Body
the request which is generated by C# does not include "soapenv:"
More over the exception "Data at the root level is invalid".
I have tried the other way, directly passing the static data by XML and got the response which means that my credentials and server is working fine. But now i have to pass values dynamically, so gotta use C# way. Any help will be appreciated and I shall be really grateful. Its getting pain in the a** -_-


Thanks in advance.


The XML request is
Expand|Select|Wrap|Line Numbers
  1. <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns="http://www.juniper.es/webservice/2007/">
  2. <soapenv:Header/> 
  3. <soapenv:Body> 
  4. <HotelAvail> 
  5. <HotelAvailRQ Version="1.1" Language="en"> <Login Email="user@mydomain.com" Password="pass" /> 
  6. <Paxes> 
  7. <Pax IdPax="1"> 
  8. <Age>50</Age>
  9.  </Pax> 
  10. </Paxes> 
  11. <HotelRequest>
  12. <SearchSegmentsHotels> 
  13. <SearchSegmentHotels Start="2013-08-20" End="2013-08-22" DestinationZone="1953"/> <CountryOfResidence>ES</CountryOfResidence> 
  14. <Boards> 
  15. <Board Type="AD"/> 
  16. </Boards> 
  17. </SearchSegmentsHotels> 
  18. <RelPaxesDist>
  19.  <RelPaxDist> 
  20. <RelPaxes> 
  21. <RelPax IdPax="1"/> 
  22. </RelPaxes> 
  23. </RelPaxDist> 
  24. </RelPaxesDist> 
  25. </HotelRequest> 
  26. </HotelAvailRQ> 
  27. </HotelAvail> 
  28. </soapenv:Body> 
  29. </soapenv:Envelope>


in C# i made like this:
Expand|Select|Wrap|Line Numbers
  1. XmlDocument XMLDoc1 = new XmlDocument();
  2.             XMLDoc1 = new System.Xml.XmlDocument();
  3.             System.Xml.XmlElement XMLRequest1;
  4.             System.Xml.XmlElement XMLsoapenv;
  5.             System.Xml.XmlElement XMLsoapenv1;
  6.             System.Xml.XmlElement XMLsoapenvHeader;
  7.             System.Xml.XmlElement XMLsoapenvBody;
  8.             System.Xml.XmlElement XMLHotelAvail;
  9.             System.Xml.XmlElement XMLHotelAvailRQ;
  10.             System.Xml.XmlElement XMLLogin;
  11.             System.Xml.XmlElement XMLPaxes;
  12.             System.Xml.XmlElement XMLPaxFirstChild;
  13.             System.Xml.XmlElement XMLHotelRequest;
  14.             System.Xml.XmlElement XMLSearchSegmentsHotels;
  15.             System.Xml.XmlElement XMLSearchSegmentHotels;
  16.             System.Xml.XmlElement XMLCountryOfResidence;
  17.             System.Xml.XmlElement XMLRelPaxesDist;
  18.             System.Xml.XmlElement XMLRelPaxDist;
  19.             System.Xml.XmlElement XMLRelPaxes;
  20.             System.Xml.XmlElement XMLRelPax;
  21.  
  22.             const string language1 = "en";
  23.             const string email = "email";
  24.             const string password = "pass";
  25.             bool showHotelInfo = true;
  26.             const string interfaceUrl1 = "URL";
  27.  
  28.             //Declaration
  29.             XmlDeclaration xmlDeclaration = XMLDoc1.CreateXmlDeclaration("1.0", "utf-8", null);
  30.             //root
  31.             XMLsoapenv = XMLDoc1.CreateElement("soapenv:Envelope");
  32.             XMLsoapenv.SetAttribute("xmlns:soapenv", "http://schemas.xmlsoap.org/soap/envelope/");
  33.             XMLsoapenv.SetAttribute("xmlns", "http://schemas.ourwebservice.com/message/");
  34.  
  35.             //header
  36.             XMLsoapenvHeader = XMLDoc1.CreateElement("soapenv:Header");
  37.             XMLsoapenv.AppendChild(XMLsoapenvHeader);
  38.             XMLsoapenvBody = XMLDoc1.CreateElement("soapenv:Body");
  39.             XMLHotelAvail = XMLDoc1.CreateElement("HotelAvail");
  40.             XMLHotelAvailRQ = XMLDoc1.CreateElement("HotelAvailRQ");
  41.             XMLHotelAvailRQ.SetAttribute("Version", "1.1");
  42.             XMLHotelAvailRQ.SetAttribute("Language", language1);
  43.             XMLLogin = XMLDoc1.CreateElement("Login");
  44.             XMLLogin.SetAttribute("Email", email);
  45.             XMLLogin.SetAttribute("Password", password);
  46.             XMLHotelAvailRQ.AppendChild(XMLLogin);
  47.             XMLPaxes = XMLDoc1.CreateElement("Paxes");
  48.             XMLPaxFirstChild = XMLDoc1.CreateElement("Pax");
  49.             XMLPaxFirstChild.SetAttribute("IdPax", "1");
  50.             XMLPaxFirstChild.SetAttribute("Age", searchCriteria.FirstChild);
  51.             XMLPaxes.AppendChild(XMLPaxFirstChild);
  52.             XMLHotelAvailRQ.AppendChild(XMLPaxes);
  53.             XMLHotelRequest = XMLDoc1.CreateElement("HotelRequest");
  54.             XMLSearchSegmentsHotels = XMLDoc1.CreateElement("SearchSegmentsHotels");
  55.             XMLSearchSegmentHotels = XMLDoc1.CreateElement("SearchSegmentHotels");
  56.             XMLSearchSegmentHotels.SetAttribute("Start", searchCriteria.CheckInDate);
  57.             XMLSearchSegmentHotels.SetAttribute("End", searchCriteria.CheckOutDate);
  58.             XMLSearchSegmentHotels.SetAttribute("DestinationZone", "628");
  59.             XMLCountryOfResidence = XMLDoc1.CreateElement("CountryOfResidence", searchCriteria.Country);
  60.             XMLSearchSegmentHotels.AppendChild(XMLCountryOfResidence);
  61.             XMLSearchSegmentsHotels.AppendChild(XMLSearchSegmentHotels);
  62.             XMLHotelRequest.AppendChild(XMLSearchSegmentsHotels);
  63.             XMLRelPaxesDist = XMLDoc1.CreateElement("RelPaxesDist");
  64.             XMLRelPaxDist = XMLDoc1.CreateElement("RelPaxDist");
  65.             XMLRelPaxes = XMLDoc1.CreateElement("RelPaxes");
  66.             XMLRelPax = XMLDoc1.CreateElement("RelPax");
  67.             XMLRelPax.SetAttribute("IdPax", "1");
  68.             XMLRelPaxes.AppendChild(XMLRelPax);
  69.             XMLRelPaxDist.AppendChild(XMLRelPaxes);
  70.             XMLRelPaxesDist.AppendChild(XMLRelPaxDist);
  71.             XMLHotelRequest.AppendChild(XMLRelPaxesDist);
  72.             XMLHotelAvailRQ.AppendChild(XMLHotelRequest);
  73.             XMLHotelAvail.AppendChild(XMLHotelAvailRQ);
  74.             XMLsoapenvBody.AppendChild(XMLHotelAvail);
  75.             XMLsoapenv.AppendChild(XMLsoapenvBody);
  76.             XMLDoc1.AppendChild(XMLsoapenv);
  77.  
  78.             HttpWebRequest request = CreateWebRequest();
  79.             XmlDocument soapEnvelopeXml = new XmlDocument();
  80.  
  81.             soapEnvelopeXml.LoadXml(XMLDoc1.ToString());
  82. try
  83.             {
  84.                 Stream stream = request.GetRequestStream();
  85.  
  86.                 soapEnvelopeXml.Save(stream);
  87.  
  88.                 WebResponse response = request.GetResponse();
  89.                 var respStream = response.GetResponseStream();
  90.                 var memStream = new MemoryStream();
  91.  
  92.                 var buffer = new byte[2048];
  93.  
  94.                 var bytesRead = 0;
  95.                 do
  96.                 {
  97.                     if (respStream != null) bytesRead = respStream.Read(buffer, 0, buffer.Length);
  98.                     memStream.Write(buffer, 0, bytesRead);
  99.                 } while (bytesRead != 0);
  100.                 if (respStream != null) respStream.Close();
  101.                 buffer = memStream.ToArray();
  102.                 string xml;
  103.                 var obj = false;
  104.                 if (buffer.Length >= 1024)
  105.                 {
  106.                     obj = true;
  107.                     xml = UnZip(buffer);
  108.                 }
  109.                 else
  110.                 {
  111.                     obj = true;
  112.                     xml = UnZip(buffer);
  113.                     //xml = System.Text.Encoding.ASCII.GetString(buffer);
  114.                 }
  115.  
  116.                 //StreamReader rd = new StreamReader(response.GetResponseStream());
  117.  
  118.                 // string soapResult = rd.ReadToEnd();
  119.                 System.IO.File.WriteAllText(@"D:\path.txt", xml);
  120.                 Console.WriteLine(xml);
  121.  
  122.  
  123.             }
  124.  
  125.             catch (WebException webex)
  126.             {
  127.                 WebResponse errResp = webex.Response;
  128.                 using (WebResponse response = request.GetResponse())
  129.                 {
  130.                     using (StreamReader rd = new StreamReader(response.GetResponseStream()))
  131.                     {
  132.                         string soapResult = rd.ReadToEnd();
  133.                         Console.WriteLine(soapResult);
  134.                     }
  135.                 }
  136.  
  137.             }

and the Functions
Expand|Select|Wrap|Line Numbers
  1.  public static string UnZip(byte[] byteArray)
  2.         {
  3.  
  4.             var uncompressed = new StringBuilder();
  5.  
  6.             using (var memoryStream = new MemoryStream(byteArray))
  7.             {
  8.                 using (var gZipStream = new GZipStream(memoryStream, CompressionMode.Decompress))
  9.                 {
  10.  
  11.                     var buffer = new byte[1024];
  12.  
  13.                     int readBytes;
  14.                     while ((readBytes = gZipStream.Read(buffer, 0, buffer.Length)) != 0)
  15.                     {
  16.                         for (var i = 0; i < readBytes; i++)
  17.                             uncompressed.Append((char)buffer[i]);
  18.                     }
  19.                 }
  20.  
  21.                 return uncompressed.ToString();
  22.             }
  23.         }
  24.  
  25. public static HttpWebRequest CreateWebRequest()
  26.         {
  27.             HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(@"http://xml2.bookingengine.es/webservice/jp/operations/availtransactions.asmx?WSDL");
  28.             webRequest.Headers.Add(@"SOAP:Action");
  29.             webRequest.ContentType = "text/xml;charset=\"utf-8\"";
  30.             webRequest.Headers.Add("Accept-Encoding", "gzip");
  31.             webRequest.Accept = "text/xml";
  32.             webRequest.Method = "POST";
  33.             return webRequest;
  34.         }
Nov 28 '16 #1
0 2490

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: manta | last post by:
I have a custom server that accepts HTTP POST requests and returns a response as the POST reply. Multiple POSTs may be outstanding at any given time. I have a client that will be sending requests...
2
by: RobertHillEDS | last post by:
While using the Soap generated ASP code, I would like to dump the raw contents of the request and response objects using Response.AppendToLog. I have tried using variations of the following code,...
5
by: Filip | last post by:
Hello, (ASP.NET c#) I want to put some common functions into one class and within this class I need to have access to the Session, Request and Response. This class is not page behind file! I...
0
by: Sebitti | last post by:
What are the default size limits for soap request and response? Can I configure the limits in application level (web service server/ client)? Are there any IIS settings that affect the limits? Do...
1
by: abcd | last post by:
I canget the value of the control on a form by using Request.form("controlName") is there anyway thru ASP object to set the value to the particular control. thanks
1
by: Gramps | last post by:
Hi, I've generated a client proxy and web service stub using WSDL.exe. All appears ok. The client proxy .cs is in the client app running in VS2005 and the web service stub is running in...
3
by: dorandoran | last post by:
Hello, I need to get the request/response pair as well as the time stamp. How do I do that? I ran a job and it's timing out so I contacted the support team and they ask me if I could provide...
8
by: samaelsh | last post by:
Hi guys! I`ve got an ASP web site that worked perfectly on a virtual server. I had to reinstall it on my computer (win XP sp2, IIS 5.1). I changed all the routes, database connection string, etc....
0
by: Joseph Geretz | last post by:
At what point in the application lifecycle should a filter be applied to the Request / Response objects? Should this be done at the start of each transaction? This would make sense if a new Request...
2
by: fj | last post by:
i am looking for tools to intercept soap request/response between server and client. Any suggestion?
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.