Read SOAP result using a loop - asp.net

I built a web service in C# web application. I'm returning list of objects as a web service result. I need to know how to read that list of items one by one in a loop.
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<checkAvailabilityResponse xmlns="http://tempuri.org/">
<checkAvailabilityResult>
<Shedule>
<Sid>int</Sid>
<Fid>int</Fid>
<FromLocation>string</FromLocation>
<FromTime>dateTime</FromTime>
<ToLocation>string</ToLocation>
<ToTime>dateTime</ToTime>
<PriceSeatA>double</PriceSeatA>
<PriceSeatB>double</PriceSeatB>
<PriceSeatC>double</PriceSeatC>
</Shedule>
<Shedule>
<Sid>int</Sid>
<Fid>int</Fid>
<FromLocation>string</FromLocation>
<FromTime>dateTime</FromTime>
<ToLocation>string</ToLocation>
<ToTime>dateTime</ToTime>
<PriceSeatA>double</PriceSeatA>
<PriceSeatB>double</PriceSeatB>
<PriceSeatC>double</PriceSeatC>
</Shedule>
</checkAvailabilityResult>
</checkAvailabilityResponse>
</soap:Body>
</soap:Envelope>
This is the way I tried:
SriLankanWebService.Service1SoapClient air1 = new AgentPortal.SriLankanWebService.Service1SoapClient();
List<Shedule> air1Response = (List<Shedule>)air1.checkAvailability(drpFrom.SelectedValue.ToString(), drpTo.SelectedValue.ToString(), DateTime.Parse(txtDepartOn.Text));
When I tried it says:
Error 1 Cannot implicitly convert type 'AgentPortal.SriLankanWebService.Shedule[]' to 'System.Collections.Generic.List<AgentPortal.Shedule>' D:\DCBSD\AgentPortal\AgentPortal\Home.aspx.cs 32 46 AgentPortal
I need to use it in a loop.

Please update your code in last line from above code from:
List<Shedule> air1Response = (List<Shedule>)air1.checkAvailability(drpFrom.SelectedValue.ToString(), drpTo.SelectedValue.ToString(), DateTime.Parse(txtDepartOn.Text));
to
AgentPortal.SriLankanWebService.Shedule[] = air1.checkAvailability(drpFrom.SelectedValue.ToString(), drpTo.SelectedValue.ToString(), DateTime.Parse(txtDepartOn.Text));
That will fix the issue.

Related

Here maps api for geocoder doesn't get the area shape for district

I used this Here Geocode API to get the area shapes for the district. However, there's no available shapes being returned on the API.
here is the link for the API
https://geocoder.ls.hereapi.com/6.2/geocode.xml?xnlp=CL_JSMv3.0.17.0&apiKey=<APIKEY>&searchtext=Cakung%20Barat%20Kel.%20Jakarta%2013910%20Indonesia&mode=retrieveAddresses&jsoncallback=H.service.jsonp.handleResponse(37)&gen=9&additionalData=IncludeShapeLevel,district
here is the response
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<ns2:Search xmlns:ns2="http://www.navteq.com/lbsp/Search-Search/4">
<Response>
<MetaInfo>
<Timestamp>2021-07-28T10:09:26.934Z</Timestamp>
</MetaInfo>
<View xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="ns2:SearchResultsViewType">
<ViewId>0</ViewId>
<Result>
<Relevance>1.0</Relevance>
<MatchLevel>district</MatchLevel>
<MatchQuality>
<Country>1.0</Country>
<City>1.0</City>
<Subdistrict>1.0</Subdistrict>
<PostalCode>1.0</PostalCode>
</MatchQuality>
<Location>
<LocationId>NT_ezpLZJFGXsz2rWjEVeA2oD</LocationId>
<LocationType>area</LocationType>
<DisplayPosition>
<Latitude>-6.16492</Latitude>
<Longitude>106.93429</Longitude>
</DisplayPosition>
<NavigationPosition>
<Latitude>-6.16492</Latitude>
<Longitude>106.93429</Longitude>
</NavigationPosition>
<MapView>
<TopLeft>
<Latitude>-6.1516</Latitude>
<Longitude>106.92209</Longitude>
</TopLeft>
<BottomRight>
<Latitude>-6.19349</Latitude>
<Longitude>106.94349</Longitude>
</BottomRight>
</MapView>
<Address>
<Label>Cakung Barat Kel., Cakung, Jakarta, Indonesia</Label>
<Country>IDN</Country>
<County>DKI Jakarta</County>
<City>Jakarta</City>
<District>Cakung</District>
<Subdistrict>Cakung Barat Kel.</Subdistrict>
<PostalCode>13910</PostalCode>
<AdditionalData key="CountryName">Indonesia</AdditionalData>
<AdditionalData key="CountyName">DKI Jakarta</AdditionalData>
</Address>
</Location>
</Result>
</View>
</Response>
</ns2:Search>
it is working for city and other options. based from the documentation, district is included on valid shape levels
We have tried to reproduce the request but it was determined as the coverage range is not supportive to get district-level shape for Jakarta.
For Example,
Demo link: https://tcs.ext.here.com/examples/v3/admin_boundaries
Also, we have documentation information with regards to coverage range.
Link: https://developer.here.com/documentation/geocoder/dev_guide/topics/coverage-geocoder.html

POST request in R: error in upload_file() with xml

I'm trying to create a POST request, but the body parameter isn't working as I expected.
The POST_bodyRequest.xml file
<?xml version="1.0" encoding="UTF-8"?>
<rs:alarm-request throttlesize="0"
xmlns:rs="http://www.ca.com/spectrum/restful/schema/request"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.ca.com/spectrum/restful/schema/request ../../../xsd/Request.xsd ">
<rs:requested-attribute id="0x10000"/>
<rs:requested-attribute id="0x10001"/>
<rs:requested-attribute id="0x10009"/>
<rs:requested-attribute id="0x1000a"/>
<rs:requested-attribute id="0x1006e"/>
<rs:requested-attribute id="0x11ee8"/>
</rs:alarm-request>
The code, basically the POST call
xml <- upload_file("POST_bodyRequest.xml")
r2 <- POST(url, login.password, body = list(xml))
status_code(r2)
First thing to note is that the content from the file isn't saved in "xml" file:
> xml <- upload_file("POST_bodyRequest.xml")
> xml
Form file: POST_bodyRequest.xml (type: application/xml)
> str(xml)
List of 2
$ path: chr "D:\\MPM\\POST_bodyRequest.xml"
$ type: chr "application/xml"
- attr(*, "class")= chr "form_file"
Therefore, the POST call returns an error
> r2 <- POST(url, login.password, body = list(xml))
Error: All components of body must be named
> status_code(r2)
[1] 415
I've also tried do read the xml file using xmlParse(). In this case, the code is recovered as expected, but I get the same error when calling POST.
> xml <- xmlParse(file = "POST_bodyRequest.xml")
> r2 <- POST(url, autenticacao, body = list(xml))
Erro: All components of body must be named
> xml
<?xml version="1.0" encoding="UTF-8"?>
<rs:alarm-request xmlns:rs="http://www.ca.com/spectrum/restful/schema/request" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" throttlesize="0" xsi:schemaLocation="http://www.ca.com/spectrum/restful/schema/request ../../../xsd/Request.xsd ">
<rs:requested-attribute id="0x10000"/>
<rs:requested-attribute id="0x10001"/>
<rs:requested-attribute id="0x10009"/>
<rs:requested-attribute id="0x1000a"/>
<rs:requested-attribute id="0x1006e"/>
<rs:requested-attribute id="0x11ee8"/>
</rs:alarm-request>
> str(list(xml))
List of 1
$ :Classes 'XMLInternalDocument', 'XMLAbstractDocument' <externalptr>
> status_code(r2)
[1] 415
I had no trouble with GET requests in R. The POST request works fine with SoapUI. So, what am I doing wrong?
Well, it did work. The problem wasn't anything related to the upload_file() function or the xml file. It was the url variable, which wasn't updated to the POST version. I'd like to thank for the confirmations and check this issue as resolved.

How to import data from XML to R?

I am a newbie in XML and R and would like to ask you for a help. I need to extract data from XML into a dataframe in R. The XML file is following:
<?xml version="1.0" encoding="UTF-8"?>
-<Report xmlns="Tlg_Table_Begin_Ende_ValueIds" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" txtHeader="Table" Name="Tlg_Table_Begin_Ende_ValueIds" xsi:schemaLocation="Tlg_Table_Begin_Ende_ValueIds http://nwlph01/ReportServer_HISTORIAN?%2FTemplates%2FPublic%2FTags%2FTlg_Table_Begin_Ende_ValueIds&rs%3AFormat=XML&rc%3ASchema=True">
-<table1 textbox7="Flags" textbox6="Quality" textbox5="Value" textbox4="Timestamp" textbox2="Tag name">
-<Detail_Collection>
<Detail Flags="8392704" Quality="128" TimeStamp2="3758.203125 " TimeStamp="3/13/2019 3:15:00 PM 3/13/2019 3:15:00 PM" TagName="SystemArchive\0101___FIT101G/UM.PV_Out#Value"/>
<Detail Flags="8392704" Quality="128" TimeStamp2="3771.9267578125 " TimeStamp="3/13/2019 3:15:01 PM 3/13/2019 3:15:01 PM" TagName="SystemArchive\0101___FIT101G/UM.PV_Out#Value"/>
<Detail Flags="8392704" Quality="128" TimeStamp2="3783.43823242188 " TimeStamp="3/13/2019 3:15:02 PM 3/13/2019 3:15:02 PM" TagName="SystemArchive\0101___FIT101G/UM.PV_Out#Value"/>
</Detail_Collection>
</table1>
</Report>
I am using following codes:
library("xml2")
df <- read_xml("lh_01.xml")
But what I receive is:
Warning message:
In doc_parse_file(con, encoding = encoding, as_html = as_html, options = options) :
xmlns: URI Tlg_Table_Begin_Ende_ValueIds is not absolute [100]
Do you have any idea what am I suppose to do?
Thank you in advance.
Searching Stackoverflow delivers e.g the folloeing URI is not absolute error - sorry I am not an XML expert what the error in your specific case may be; my know-how only goes so far as to find your xmlns URI unusual.

How to run Method1 present in 100 classes in package using testng.xml?

I have to Run the Method1 in Package whose structure looks like
Package - Regression
|--class1
|-method1
|-method2
|--class2
|-method1
|-method2
|--class3
.
.
and so on goes to classN where N can be from 100 to 2000.
Now I need to write the testNG.xml is such a way that method1 present in all the classes execute at package level
or In future If i need to execute method1 and method2 at package level ?
Thanks in advance for solution
You can do this very easily using a beanshell method selector.
Here's a sample
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="54859054_suite" verbose="2">
<method-selectors>
<method-selector>
<script language="beanshell">
<![CDATA[
whatMethod = System.getProperty("methodToExecute", "testMethod1");
method.getName().equals(whatMethod);
]]>
</script>
</method-selector>
</method-selectors>
<test name="54859054_test">
<packages>
<package name="com.rationaleemotions.stackoverflow.qn54859054"/>
</packages>
</test>
</suite>
The above beanshell by default will execute methods whose name is "testMethod1" (since its the default value we have provided for the JVM argument methodToExecute.
If you would like to change its value in run-time, you merely pass a new value via the JVM arugment. For e.g., -DmethodToExecute=testMethod2

Generating XML dynamically from the data entered on UI

I have a xml file which is currently made manually and I have to make a functionality(UI) where user can enter the data and I have to store the data and generate the xml file dynamically in .NET.
Problem is the format of the xml file. I am not able to decide how I am going to store that data and then dynamically generate xml from that.
Please find the some of the extract of the code from the xml file below:
<?xml version="1.0" encoding="UTF-8"?>
<DATA>
<SDACTS>
<SDACT TYPE="Economy" COLOUR="0xff0000"/>
<SDACT TYPE="Environment" COLOUR="0x00ff00"/>
<SDACT TYPE="People" COLOUR="0x0000ff"/>
<SDACT TYPE="Society" COLOUR="0xff00ff"/>
</SDACTS>
<INDUSTRIES>
<INDUSTRY TYPE="Platinum" COLOUR="0x0094B1">
<PRODUCT>Platinum</PRODUCT>
<PRODUCT>Palladium</PRODUCT>
<PRODUCT>Rhodium</PRODUCT>
<PRODUCT>Gold</PRODUCT>
</INDUSTRY>
<INDUSTRY TYPE="Diamonds" COLOUR="0x652382">
<PRODUCT>Diamonds</PRODUCT>
</INDUSTRY>
<INDUSTRY TYPE="Metallurgical Coal" COLOUR="0x999a8f">
<PRODUCT>Metallurgical Coal</PRODUCT>
</INDUSTRY>
</INDUSTRIES>
<LOCATIONS>
<CONTINENT TITLE="South America">
<COUNTRY TITLE="Brazil">
<HEADOFFICE>So Paulo</HEADOFFICE>
<ADDRESS>
Sau, polo, ambikaui
</ADDRESS>
<LATITUDE>-23.571157</LATITUDE>
<LONGITUDE>-46.644146</LONGITUDE>
<BUSINESSUNITS>Nickel; Iron ore and manganese</BUSINESSUNITS>
<DESCRIPTION>Anglo American has been operating in Brazil since 1973. Our core operations are involved in the production of nickel, iron ore and maganese, while our interests in the production of phosphates and niobium at Copebras and Catalo respectively have been identified for divestment. Nickel projects in the pipeline include Barro Alto.</DESCRIPTION>
<EMPLOYEES/>
<NUMBEROFBUSINESS>2</NUMBEROFBUSINESS>
<!--New project added - 12/02/2010 start -->
<PROJECT>
<TYPE>Greenfield</TYPE>
<NAME>Minas Rio expansion</NAME>
<UNITTYPE>Iron Ore and Manganese</UNITTYPE>
<RELATEDOPERATION>Greenfield</RELATEDOPERATION>
<LATITUDE>-18.92814</LATITUDE>
<LONGITUDE>-43.42562</LONGITUDE>
<STATUS>Future unapproved</STATUS>
<DESCRIPTION/>
<FULLPRODUCTIONDATE>TBD</FULLPRODUCTIONDATE>
<PRODUCTIONVOLUME>Up to 53 Mtpa iron ore pellet feed (wet basis)</PRODUCTIONVOLUME>
<!-- <ESTIMATEDCAPEX>TBD</ESTIMATEDCAPEX>-->
<FOOTNOTES>
<![CDATA[1. Capital expenditure shown on 100% basis in nominal terms. Platinum projects reflect approved capex.<br><br>2. Production volume represents 100% of average incremental or replacement production, at full production, unless otherwise stated.]]>
</FOOTNOTES>
</PROJECT>
<SDACTIVITY>
<ID>3.2.4.20</ID>
<TYPE>Society</TYPE>
<BUSINESS>Nickel</BUSINESS>
<RELATEDOPERATION/>
<HEADING>Listening - and acting - in Brazil</HEADING>
<SUBHEADING>SEAT community engagement session in Brazil</SUBHEADING>
<COPY>
local government.
</COPY>
<IMAGE>3.2.4.20.jpg</IMAGE>
<LINKCAPTION>Read more about SEAT in Brazil</LINKCAPTION>
<LINKURL>http://www.angloamerican.co.uk/aa/development/case-studies/society/society01/</LINKURL>
</SDACTIVITY>
</COUNTRY>
</CONTINENT>
</LOCATIONS>
</DATA>
You could just store it directly in the DOM, and serialise when desired.
If I were you I would just store the data in a db and then use an xmltexwriter to write it to where ever.
using (XmlTextWriter writer = new XmlTextWriter(OutputStream, Encoding.UTF8)) {
writer.Formatting = Formatting.Indented;
writer.WriteStartDocument();
writer.WriteStartElement("DATA");
writer.WriteStartElement("SDACTS");
foreach ( SDACT in SDACTs) {
writer.WriteStartElement("SDACT");
writer.WriteAttributeString("TYPE", SDACT.Type);
writer.WriteAttributeString("COLOUR", SDACT.COLOUR);
writer.WriteEndElement();
}
writer.WriteEndElement();
writer.WriteEndElement();
writer.WriteEndDocument();
}
You could also take advantage of using .nets XML serialization see http://msdn.microsoft.com/en-us/library/ms950721.aspx

Resources