Cendris is offering a (paid) web service to validate Dutch ZIP codes. A bump in using it is that it does not offer goodies like wsdl like we are used to in the .NET implementation of web services. Cendris uses classical XML-RPC. But you don't have to (dis-)assemble the request and responses yourself. Charles Cook has a nice tool available which will (amongst other things) create proxies for the XML-RPC on the fly in your code. It comes with clear examples and consists of one assembly. You define your proxy by declaring an interface describing it. You define the in and out parameters by declaring structs describing them.
It took me some time to find the declarations for the Cendris ZIP services. The main problem was the Cendris documentation. All method and param names are case-sensitive and in the docs are some casing errors. The docs do contains full examples of a request and response. But these are in non-indented XML and are rendered very badly in the PDF. So I'll reproduce my full declarations here
using
System;
using CookComputing.XmlRpc;
struct CendrisPostCodeUit
{
public string straatnaam;
public string huisnummer;
public string postcode;
public string woonplaats;
public string netnummer;
public string status;
}
struct
CendrisAdresUit
{
public string straatnaam;
public string huisnummer;
public string postcode;
public string woonplaats;
public string netnummer;
public string match;
}
struct CendrisPostCodeIn
{
public string username;
public string password;
public string postcode;
public string huisnummer;
}
struct
CendrisCheckAdresIn
{
public string username;
public string password;
public string straatnaam;
public string huisnummer;
public string woonplaats;
}
[XmlRpcUrl(http://www.dataonline.nl/adresxpress/server/adresxpress_server.php)]
interface IcendrisPostcode
{
[XmlRpcMethod("adresxpress.postcode")]
CendrisPostCodeUit PostCode(CendrisPostCodeIn request);
[XmlRpcMethod("adresxpress.checkadres")]
CendrisAdresUit[] CheckAdres(CendrisCheckAdresIn request);
}
You use the service by creating a proxy, typecasting it to the interface and then call the interfaces methods
IcendrisPostcode cendris = (IcendrisPostcode) XmlRpcProxyGen.Create(typeof(IcendrisPostcode));
CendrisPostCodeIn request;
request.username = "yourusername";
request.password = "yourpwd";
request.postcode = textBoxPC.Text;
request.huisnummer = textBoxNummer.Text;
try
{
CendrisPostCodeUit res = cendris.PostCode(request);
textBoxStraat.Text = res.straatnaam;
textBoxNummer.Text = res.huisnummer;
textBoxPC.Text = res.postcode;
textBoxPlaats.Text = res.woonplaats;
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
The service not only checks the zipcode but also transforms all address data to (NEN) standard notation.
It took some fiddling, but now its working like a snap. Who needs pv ?
Peter
Posted
04-19-2004 1:09 PM
by
pvanooijen