Answered by:
how to parse Soap Envelope in c#

Question
-
User-171003712 posted
Hello i am getting soap Envelope This is my Soap responce
How to parse in c# by XML n by linq i have no idea how to parse and maintain data
This is sample in my responce its come 100 HotelAvailability nodes come
so please give me some code or idea to maintain this
Thanks
Tuesday, May 21, 2013 5:51 AM
Answers
-
User-1800438376 posted
since you are using web services generate using wsdl instead of svcutil and write code for the same.
replace svcutil -i with wsdl
//service url contains both sync and async calls //one of the sync call are as follows AuthorityElement objElement = new AuthorityElement(); //specify the objElement values here RegionSearch objSearch = new RegionSearch(); objSearch.RegionId = 1; objSearch.RegionName = "TTT"; objSearch.ParentRegionId = 2; objSearch.ParentRegionName = "YYYY"; objSearch.Authority =objElement; objSearch.DepthChildren = "4"; objSearch.DepthParents = "5"; Service objClient = new Service(); RegionElement[] arrRegionElement = objClient.RegionSearch(objSearch);- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Tuesday, May 28, 2013 8:58 AM
All replies
-
User-649116597 posted
can you post your code. how to get response??
Tuesday, May 21, 2013 7:08 AM -
User-1800438376 posted
why you want to parse?
can't you use svcutilutil to generate proxy.
Tuesday, May 21, 2013 7:29 AM -
User-171003712 posted
this is my code
public static string CallWebService()
{
var _url = "http://xxxxxxxxxxxx/RXLStagingServicesV212/ASMX/XmlService.asmx";
var _action = " http://xxxxxxxxxxxx/namespace/WebServices/Xml/AvailabilitySearch";
XmlDocument soapEnvelopeXml = CreateSoapEnvelope();
HttpWebRequest webRequest = CreateWebRequest(_url, _action);
InsertSoapEnvelopeIntoWebRequest(soapEnvelopeXml, webRequest);
// begin async call to web request.
IAsyncResult asyncResult = webRequest.BeginGetResponse(null, null);
// suspend this thread until call is complete. You might want to
// do something usefull here like update your UI.
asyncResult.AsyncWaitHandle.WaitOne();
// get the response from the completed web request.
string soapResult;
using (WebResponse webResponse = webRequest.EndGetResponse(asyncResult))
using (StreamReader rd = new StreamReader(webResponse.GetResponseStream()))
{
soapResult = rd.ReadToEnd();
}
return soapResult;
}
private static HttpWebRequest CreateWebRequest(string url, string action)
{
HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(url);
webRequest.Headers.Add("SOAPAction", action);
webRequest.ContentType = "text/xml;charset=\"utf-8\"";
webRequest.Accept = "text/xml";
webRequest.Method = "POST";
return webRequest;
}
private static void InsertSoapEnvelopeIntoWebRequest(XmlDocument soapEnvelopeXml, HttpWebRequest webRequest)
{
using (Stream stream = webRequest.GetRequestStream())
{
soapEnvelopeXml.Save(stream);
}
}Tuesday, May 21, 2013 10:40 AM -
User-171003712 posted
Hello luckyforu2006
I have no idea about svcutilutil
please tell me how to use this to my webservice
Thanks
Tuesday, May 21, 2013 10:42 AM -
User-649116597 posted
Try this code :- Edit according to your requirement.
XmlDocument xmldoc = new XmlDocument(); using (HttpWebResponse response = (HttpWebResponse)request.GetResponse()) { StreamReader responsereader = new StreamReader(response.GetResponseStream()); var responsedata = responsereader.ReadToEnd(); var serializer = new XmlSerializer(typeof(LatestBookings[]),new XmlRootAttribute("GetLatestBookingsDetailsResult")); var GetLatestBookingsDetailsResult = (LatestBookings[])serializer.Deserialize(responsereader); //xmldoc.Save(@"D:\Output\myfile.xml"); //xmldoc.Load(@"D:\Output\myfile.xml"); DataSet ds = new DataSet(); //ds.ReadXml(Request.PhysicalApplicationPath + "myfile.xml"); GridView1.DataSource = ds.Tables["LatestBookingDetails"]; GridView1.DataBind(); //responsereader.Close(); //request.GetResponse().Close(); }
Wednesday, May 22, 2013 4:20 AM -
User-171003712 posted
thanks
Monday, May 27, 2013 11:40 AM -
User-1800438376 posted
1. start--> visual studio command prompt
2. type svcutil -i http://roomsxmldemo.com/RXLStagingServicesV212/ASMX/XmlService.asmx
this will create proxy file service.cs and output.config.2. create the object of public method and start executing the commands.
I need more details to help you ?
which public method you are calling and what is the return output. post some code samples.
Tuesday, May 28, 2013 1:59 AM -
User-171003712 posted
thanks
as you said i have done and got two files service.cs,output.config
now tell me how i call this
thanks
Tuesday, May 28, 2013 5:54 AM -
User-1800438376 posted
since you are using web services generate using wsdl instead of svcutil and write code for the same.
replace svcutil -i with wsdl
//service url contains both sync and async calls //one of the sync call are as follows AuthorityElement objElement = new AuthorityElement(); //specify the objElement values here RegionSearch objSearch = new RegionSearch(); objSearch.RegionId = 1; objSearch.RegionName = "TTT"; objSearch.ParentRegionId = 2; objSearch.ParentRegionName = "YYYY"; objSearch.Authority =objElement; objSearch.DepthChildren = "4"; objSearch.DepthParents = "5"; Service objClient = new Service(); RegionElement[] arrRegionElement = objClient.RegionSearch(objSearch);- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Tuesday, May 28, 2013 8:58 AM -
User-171003712 posted
thanks
Tuesday, May 28, 2013 3:04 PM