views:

221

answers:

2

Hello guys! I have a url which normally points to a postcode lookup webservice:

"http://pce.afd.co.uk/afddata.pce?Serial=822590&Password=<PASSWORD>&UserID=<UNAME>&Data=Address&Task=PropertyLookup&Fields=List&MaxQuantity=200&Lookup=BD1+3RA"

I need to make a call to this url, probably by using HttWebRequest and get the output which is an xml string (see example):

<?xml version="1.0"?>
<AFDPostcodeEverywhere>
<Result>1</Result><ErrorText></ErrorText><Item value="1"><Postcode>BD1 3RA</Postcode>
<PostcodeFrom></PostcodeFrom>
<Key>BD1 3RA1001</Key>
<List>BD1 3RA     City of Bradford Metropolitan District Council, Fountain Hall, Fountain Street, BRADFORD</List>
<CountryISO>GBR</CountryISO>
</Item>
</AFDPostcodeEverywhere>

My problem is that when I type the url in my browser, I get the xml above in my browser but I am not able to get this xml string via code. CAN ANYONE HELP ME OUT PLZ!!! ITS REALLY VERY URGENT! From what I have read we need to make a soap request but I dnt know how to do that!!! Thanks in advance!

+1  A: 

Personally, I prefer to use XDocument.Load method and then use LINQ-to-XML to read through the results. It's cleaner than other parsing mechanisms in the .NET framework.

var xmlDoc = XDocument.Load("http://pce.afd.co.uk/afddata.pce?Serial=822590&amp;Password=&lt;PASSWORD&gt;&amp;UserID=&lt;UNAME&gt;&amp;Data=Address&amp;Task=PropertyLookup&amp;Fields=List&amp;MaxQuantity=200&amp;Lookup=BD1+3RA");

You could then use LINQ to parse the results or, alternatively, call ToString() to get the XML as a string.

mkedobbs
Suraj
+1  A: 

You can get the XML response from the HttpWebResponse object (under the System.Net namespace if I can remember).

To get a HttpWebResponse you first have to build up a HttpWebRequest object.

See:

And you can use the following code to convert the response into an XMLDocument that you can traverse:

HttpWebRequest HttpWReq = (HttpWebRequest)WebRequest.Create("http://pce.afd.co.uk/afddata.pce?...");
using (HttpWebResponse HttpWResp = (HttpWebResponse)HttpWReq.GetResponse())
{
       XmlDocument xmlDoc = new XmlDocument();
       xmlDoc.Load(HttpWResp.GetResponseStream());
}

EDIT (1):

The company in question appear to have an ASMX webservice that you will be able to consume in your .NET application to get to the neccessary data.

You'll need the password and serial number (which you can get from the URL).

Robert W
Can you provide me with a code sample plz because I have tried this but i could not retrieve the xml string, instead of that i got the html for the page found in the url "http://pce.afd.co.uk/", if you look at the web service url, you will notice that it is part of the web service url. Is it possible that the url is causing the problem?
Suraj
what's the output type of the page you're requesting (i.e. when you go to the URL does it serve the XML immediately, or do you need to click through a number of other pages to get to the XML? The above example will assume it's XML. It's also worth checking to see if the company in question has an API - will be a lot easier.
Robert W
Have a look here: http://ws.afd.co.uk/. They appear to have an ASMX webserice.
Robert W
Thanks for the help Robert, i was not aware of the asmx web service. I will try this one :)
Suraj