How to populate XML node values in Grid view in Asp.net? - web-services

I am using a thirdparty webservice. I got the response in XML format.
Now, i have to show the XML node values in grid view.
The following code i tried so far.
using (HttpWebResponse response = request.GetResponse() as HttpWebResponse)
{
// Get the response stream
StreamReader reader = new StreamReader(response.GetResponseStream());
//Label2.Text = reader.ReadToEnd();
XmlDocument xml = new XmlDocument();
xml.Load(reader);
XmlNamespaceManager ns = new XmlNamespaceManager(xml.NameTable);
ns.AddNamespace("ms", "http://webservices.amazon.com/AWSECommerceService/2005-10-05");
XmlNode image = xml.SelectSingleNode("//ms:URL", ns);
XmlNode FormattedPrice = xml.SelectSingleNode("//ms:FormattedPrice", ns);
Now, i want to show the values of XMLnode value in grid view.
Please inform me, if you need more information.
Thanks in advance.

You can use an XMLDataSourcefor that:
http://www.codeproject.com/Articles/10898/Introduction-to-XMLDataSource-control-in-ASP-NET-2
Best regards.

Solution:
Instead of Get the HttpResponse in xmldocument.
I used XNamespace and XDocument.
XNamespace ns = "http://webservices.amazon.com/AWSECommerceService/2005-10-05"; // Linq
XDocument xd = XDocument.Load(response.GetResponseStream());
Then Use Linq to Read all Vlaues. Example:
var Image = xd.Descendants(ns + "Items").Elements(ns + "Item").Select(img => img.Elements(ns + "MediumImage").Select(img1 => (string)img1.Element(ns + "URL")).FirstOrDefault() ?? "Null").ToList();

Related

Web service callout failed: Unexpected element. Parser was expecting element 'http://schemas.xmlsoap.org/soap/envelope/:Envelope' but found ':HTML'

while make a webservice call out I am getting below error:
Web service callout failed: Unexpected element. Parser was expecting element 'http://schemas.xmlsoap.org/soap/envelope/:Envelope' but found ':HTML'
Please see below code which I am trying for this:
public class TestUtility_Cls{
public list<Test_webService.KeyValuePair> IOG_pair = new list<Test_webService.KeyValuePair>();
public pageReference calltestServices(){
I_pair = new list<Test_webService.KeyValuePair>();
Test_webService.webPort bindobj = new Test_Iwebervice.RtPort();
bindobj.clientCertName_x = 'xxxxxxxxxxxxxx';
bindobj.timeout_x = 120000;
bindobj.inputHttpHeaders_x = new Map<String, String>();
bindobj.inputHttpHeaders_x.put('Authorization', 'xxxxxxxxx');
Test_webService.KeyValuePair I_KeyValue = new Test_webService.KeyValuePair();
I_KeyValue.key = 'SessionId';
I_KeyValue.value = 'Carrie09';
I_pair.add(I_KeyValue);
I_KeyValue = new Test_webService.KeyValuePair();
I_KeyValue.key = 'CR';
I_KeyValue.value = 'ExOffer';
I_pair.add(I_KeyValue);
Test_webService.ArrayOfKeyValuePair kevapair = new Test_webService.ArrayOfKeyValuePair();
kevapair.attribute = I_pair;
Test_webService.ProcessEventResponse_element IResp = new Test_webService.ProcessEventResponse_element();
IResp = bindingobj.ProcessEvent('QA', 'GetOffers', kevapair);
return null;
}
}
Here I am using WSDL generated class's method.
Can someone help on this. How to resolve it?
Thanks,
public pageReference calltestServices(){
I think above method refers a html page reference from which you are extracting your input data.You are forming your input request in html format while your webservice is expectng soap envelope. I think you need to wrap or convet or edit your request, formed in above method as soap envelope, then only your server accept it.

How to specify language, location and city with facebook graph api

I am using FacebookGraphAPIDesktop.swc api to create unpublished post.
How can I assign language, location and city parameter with it?
Currently I am creating it like below :-
var params:Object = new Object();
params.access_token = PhotoToken;
params.published = 0;
params.message = "Test unpublished post";
FacebookDesktop.api("/" + PageID +"/feed", StatusPosted, params,"POST");
thanks in advance
I found the solution and posting here if anyone needs it :-
We need to pass it as a json string :-
var targeting:String = "{'countries':['US','IN']}";
_params.access_token = token;
_params.published = 0;
_params.message = "This is status message 5";
_params.targeting = targeting;
FacebookDesktop.api("/202387076493582/feed", messagePosted1, _params,"POST");

Why is this CAML Query is not filtering results from SharePoint Web Service call?

I am trying to filter the list of results returned by the following web service call to a SharePoint list. When I have
query.InnerText = "";
the results include every row in the SharePoint list - including rows having an IN SERVICE DATE less than today, greater than today, or no value at all. I need the CAML query to filter, but adding the Where statement does not work.
service.Url = url;
String pipeProjectSummaryListGuid = "{2D193799-F1FB-46B1-A313-56B8B12E1111}";
XmlDocument xmlDoc = new System.Xml.XmlDocument();
XmlElement query = xmlDoc.CreateElement("Query");
XmlElement viewFields = xmlDoc.CreateElement("ViewFields");
XmlElement queryOptions = xmlDoc.CreateElement("QueryOptions");
String rowLimit = "9000";
query.InnerText = "<Where><Gt><FieldRef Name=\"In_x0020_Service_x0020_Date\" /><Value Type=\"DateTime\"><Today /></Value></Gt></Where>";
viewFields.InnerXml = "<FieldRef Name=\"NEW_ID\" /><FieldRef Name=\"In_x0020_Service_x0020_Date\" /><FieldRef Name=\"ProjectPriority\" />";
queryOptions.InnerXml = "<ViewAttributes Scope=\"Recursive\" /><IncludeMandatoryColumns>FALSE</IncludeMandatoryColumns>";
try
{
results = service.GetListItems(pipeProjectSummaryListGuid, null, query, viewFields, rowLimit, queryOptions, null);
}
Try using query.InnerXml instead of query.InnerText.

XmlSerializer with custom transform using XSLT

Is there a way to deserialize a XML stream using XmlSerializer by applying a custom transform defined in a XSLT?
I don't think there is a single API call that would allow that but you could certainly implement that with a few lines along the following approach:
XslCompiledTransform proc = new XslCompiledTransform();
proc.Load("sheet.xsl");
XmlDocument tempResult = new XmlDocument();
using (XmlWriter xw = tempResult.CreateNavigator().AppendChild())
{
proc.Transform("input.xml", null, xw);
xw.Close();
}
XmlSerializer ser = new XmlSerializer(typeof(Foo));
Foo foo = (Foo)ser.Deserialize(new XmlNodeReader(tempResult));

SharePoint web services: test if file exists

I'm using SharePoint web services in C#. I have my code working to check files and check them out using the Lists web service. I need to test to see if a file exists; I can find lots of examples for doing this using the object model API, but I can't seem to find a straightforward way of doing this using web services.
Try the Lists.GetListItems with a suitable CAML query.
A CAML query like
<Query><Where><Eq><FieldRef Name="FileLeafRef" /><Value Type="Text">Filename.rtf</Value></Eq></Where></Query>
should work; the field 'FileLeafRef' is where the filename is stored.
This code may do, it's a little rough, but demonstrates how to get a list of files based on the title.
public static bool PageExists(string listName, string webPath, string pageTitle)
{
string pageId = "";
IntranetLists.Lists lists = new IntranetLists.Lists();
lists.UseDefaultCredentials = true;
lists.Url = webPath + "/_vti_bin/lists.asmx";
XmlDocument doc = new XmlDocument();
doc.LoadXml("<Document><Query><Where><Contains><FieldRef Name=\"Title\" /><Value Type=\"Text\">" + pageTitle + "</Value></Contains></Where></Query><ViewFields /><QueryOptions /></Document>");
XmlNode listQuery = doc.SelectSingleNode("//Query");
XmlNode listViewFields = doc.SelectSingleNode("//ViewFields");
XmlNode listQueryOptions = doc.SelectSingleNode("//QueryOptions");
Guid g = GetWebID(webPath);
XmlNode items = lists.GetListItems(listName, string.Empty, listQuery, listViewFields, string.Empty, listQueryOptions, g.ToString());
}
return items.Count > 0;
}
public static XmlNodeList XpathQuery(XmlNode xmlToQuery, string xPathQuery)
{
XmlDocument doc = new XmlDocument();
doc.LoadXml(xmlToQuery.OuterXml);
XmlNamespaceManager mg = new XmlNamespaceManager(doc.NameTable);
mg.AddNamespace("sp", "http://schemas.microsoft.com/sharepoint/soap/");
mg.AddNamespace("z", "#RowsetSchema");
mg.AddNamespace("rs", "urn:schemas-microsoft-com:rowset");
mg.AddNamespace("y", "http://schemas.microsoft.com/sharepoint/soap/ois");
mg.AddNamespace("w", "http://schemas.microsoft.com/WebPart/v2");
mg.AddNamespace("d", "http://schemas.microsoft.com/sharepoint/soap/directory");
return doc.SelectNodes(xPathQuery, mg);
}
I also had similiar problems with this.
I have tried the following FieldRefs without success: "Name", "FileLeafRef" and "LinkFilenameNoMenu".
The post located at http://www.johanolivier.blogspot.com details what I had to do to get it working.