Contact ePostcode.com on +44 (0)845 094 2633  
  
ASPNet, C# and VB.Net

Getting started with .net

Using .net technology to consume the ePostcode web service is very simple.

Microsoft.net makes life easy for us by handling the SOAP communication and building a Proxy class to wrapper the web service.


 
The first thing you will need to do within your .net project is add a reference to the ePostcode Web Service as follows:



At the Add Web Reference Dialog enter the following URL 

http://ws.epostcode.com/uk/postcodeservices.asmx

and press the 'Go' button.
Change the Web reference name to ePostcode.

Press the 'Add Reference' button.

When you add the Web Reference a proxy class is created and can be viewed by opening the Reference.cs (Reference.vb in VB.net) in code view.



In this example we are using the SearchPremise_ByPostcode and GetPremiseAddress methods of the ePostcode web service to return a list of Addresses on a Postcode Search and retrieving the Full Postal Address of the Selected Address.

At the point in your code where you want to return the List of Addresses put in the following code. For this example the code is inside the Click Event of a Button control as follows:

C# Example


ePostcode.PostcodeServices objTest = new ePostcode.PostcodeServices();

ePostcode.PostcodeUtilities.ListAddressPremiseDataTable mySearch=objTest.SearchPremise_ByPostcode_Dataset(txtSearchPostcode.Text,msAccountName,msLicenceID,"").ListAddressPremise;
   
lstAddresses.Items.Clear();
foreach (ePostcode.PostcodeUtilities.ListAddressPremiseRow objRow in mySearch.Rows)
{
 if (objRow.Return_Code=="1")
 {
  lstAddresses.Items.Add(new ListItem(objRow.List_Address,objRow.Unique_Delivery_Point));
 }
 else
 {
  lstAddresses.Items.Add(new ListItem(objRow.Return_Code,objRow.Return_Code));
 }
}

if (objTest != null)
{
 objTest.Dispose();
}


At the point in your code where you want to get a Full Postal Addresses from the list box (e.g. in the SelectedIndexChanged Event of the listbox) put in the following code:

C# Example


ePostcode.PostcodeServices objTest = new ePostcode.PostcodeServices();
   
ePostcode.PostcodeUtilities.AddressPremiseDataTable mySearch=objTest.GetPremiseAddress_Dataset(lstAddresses.SelectedItem.Value,msAccountNameDemo,msGUIDDemo,"").AddressPremise;
   
if (mySearch.Rows.Count>0)
{
 foreach (ePostcode.PostcodeUtilities.AddressPremiseRow objRow in mySearch.Rows)
 {
  if (objRow.Return_Code=="1")
  {
   txt0.Text=objRow.Unique_Delivery_Point;
   txt1.Text=objRow.Organisation_Department;
   txt2.Text=objRow.Organisation;
   txt3.Text=objRow.Sub_Building_Name;
   txt4.Text=objRow.Building_Name;
   txt5.Text=objRow.Number;
   txt6.Text=objRow.Dependent_Street;
   txt7.Text=objRow.Street;
   txt8.Text=objRow.Double_Dependent_Locality;
   txt9.Text=objRow.Dependent_Locality;
   txt10.Text=objRow.Post_Town;
   txt11.Text=objRow.County_LocalAuthority;
   txt12.Text=objRow.Country;
   txt13.Text=objRow.Postcode;
   txt14.Text=objRow.Delivery_Point_Suffix;
   txt15.Text=objRow.Post_Office_Box;
   txt16.Text=objRow.User_Category;
   txt17.Text=objRow.Mailsort_Sortcode;
  }
 }
}

if (objTest != null)
{
 objTest.Dispose();
}



If you have not already signed-up for an account click here Sign-Up Now.
You will receive your Access Codes by email and you will receive 50 free credits.

When you have your Access Codes ready, you will need to change the following values in the Web.config to get the code above to work:

<add key="DemoAccountName" value="XXXXXXXX" />
<add key="DemoGUID" value="XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" />

Change the XXXXXXXX value to be your eSortcode AccountName.
Change the XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX value to be your eSortcode GUID.

Remember and add the following lines into the Page_Load Event

msGUIDDemo=ConfigurationSettings.AppSettings["DemoGuid"];
msAccountNameDemo=ConfigurationSettings.AppSettings["DemoAccountName"];


It's that simple.

The other methods of the ePostcode Web Service can be used in a similar way.

For a full technical description of the ePostcode web service and the 3 methods click on the following link Web Service Described

If you have any questions feel free to contact us at the following link Contact Us.