WebService in WinApp c#

Associate
Joined
27 Jan 2005
Posts
1,390
Location
S. Yorks
We have a webservice that I can call from a webpage via an ajax call

Code:
    $.ajax({
                type: "GET",
                url: "http://server/GetPostcodes.svc/xml/" + ID,
                contentType: "text/xml; charset=utf-8",
                async: true,

                success: function (data) {
                        var parser = new DOMParser();
                        var xmlDoc = parser.parseFromString(data.childNodes[0].textContent,"text/xml");
                        var xmlResultCount = xmlDoc.childNodes[0].childElementCount;
                        
                        var columnHeadArray = ["Street 1", "Street 2", "Street 3", "City", "Country", "Postcode"];

                        bindData(tableID, columnHeadArray);
                        ....

It returns an address from a postcode or partial postcode given to it.

We want to reuse this service in a windows forms app - how can I call this service and parse the results via the winapp?


Matt
 
Ok got:

Code:
WebRequest webRequest = WebRequest.Create("http://server/GetPostcodes.svc/xml/DN12");
WebResponse webResp = webRequest.GetResponse();

Stream dstream = webResp.GetResponseStream();

It's just parsing the resulting stream into a datatable?

Matt
 
Thanks for the reply.

I can now iterate over the text returned but googling suggests I can use desrialise to do what I am trying to do, however my returned xml looks like this:

Code:
<?xml version="1.0" encoding="utf-16"?>
<ArrayOfPostcodes xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <Postcodes>
    <PostCode>DN16 8BD</PostCode>
    <Street1>1 Kings Grove </Street1>
    <Street2>Denaby</Street2>
    <Street3 />
    <City>Doncaster</City>
    <Country>United Kingdon</Country>
  </Postcodes>

Note the <Arrayofpostcodes, is this ill formed should there be a root or???

Am new to this so struggling my way through it at the moment.


Matt
 
chroniclard,

That example was superb, thanks.

So as the first three lines of the xml are:
Code:
<?xml version="1.0" encoding="utf-16"?>
<ArrayOfPostcodes xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<Postcodes>


With the last line being
Code:
</Postcodes>
</ArrayOfPostcodes>


I assume I would create a class for ArrayofPostcodes, but what about the first line?

Matt
 
Shoeyuk,

.ApplicationClient I have no option for that only my methods from the service - .GetPostcodesClient, .IGetPostcodes, .IGetPostcodesChannel. have you added the ApllicationClien?

Matt
 
Shoeyuk,

I've created:

GetPostcodesServiceReference1.GetPostcodesClient getPostcodesClient = new GetPostcodesServiceReference1.GetPostcodesClient();

but it errors with "System.InvalidOperationException: 'Could not find default endpoint element that references contract 'GetPostcodesServiceReference1.IGetPostcodes' in the ServiceModel client configuration section. This might be because no configuration file was found for your application, or because no endpoint element matching this contract could be found in the client element.'"

Googling this I appear to be missing config in my app.config file, if so what do I add in here - getting way beyond my knowledge here now.

Matt
 
Ah added the link in app.config but getting a

'The communication object, System.ServiceModel.ChannelFactory`1[GetPostcodesServiceReference1.IGetPostcodes], cannot be used for communication because it is in the Faulted state.'

???


Matt
 
Back
Top Bottom